How Do You Troubleshoot a C Program That Prints a Warning Message like “expects argument of type ‘char*’, but argument 2 has type ‘int’ [-Wformat=]”?

Problem scenario
You compile a C program (with gcc foobar.cc) but you get an error message like this:

“foofbar1.cc:71…: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘int’ [-Wformat=]
   printf (“y is a %s\n”, y);
                           ^  “

What do you do to not get this error?

Solution
While the code compiles, the executable may not run. 

How Do You Eliminate the “Namespace”, Quotes and Brackets from the Variable You Are Printing with Python?

Problem scenario
You are trying to print a variable, but it prints out like this:

Namespace(string=[‘foobar’])

How do you print out just “foobar” with no quotes?

Solution

Overview
The key word here is “string”.  The “string” text in this is the attribute you will want.

Background
Your program may have something like this:

args = parser.parse.args() # Assuming this is the variable assignment of “foobar”
print (args)

 Procedures
1. 

How Do You Troubleshoot Sonarqube Not Starting with Log Messages about “failed to load plugin”?

Problem scenario
You are using SonarQube Community Edition.  SonarQube will not start.  You recently moved a .jar file into a plugins directory.  You want to use this plugin to analyze code.  

The SonarQube logs may register something like “Background initialization failed. Stopping SonarQube java.lang.IllegalStateException: Fail to load plugin C / C++ / Objective-C [cpp]”

The logs may also say something like this: “Unable to register extension com.A.A.A.B.F from plugin ‘cpp’ or “NoClassFoundError…PropertiesDao”.

How Do You Troubleshoot the Error “java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver”?

Problem scenario
You run a Java program and receive “java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver”.  You need to get a program working despite reading that this driver has been deprecated.  What should you do?

Solution
1.  Find the JRE/lib/ext directory.  
2.  Place an ojdbc14.jar file (e.g., downloaded from Oracle.com or some trustworthy website) in that directory.
3.  Without recompiling your program, run the Java program again.

How Do You Install pip or pip3?

Problem scenario
You think you installed pip (e.g., using this posting for Debian/Ubuntu, using this posting with Linux SUSE, using this posting for a CentOS/RHEL/Fedora server, or this posting as an alternative), but when you run pip, you get “command not found.”  How do you install pip and get it working?

Solution
pip or pip3 may actually be installed despite the fact that things may seem otherwise. 

What Is the Python Requests Syntax Equivalent of a curl “-X DELETE”?

Problem scenario
You are invoking requests.get() in a Python program (after an “import requests” statement near the top of your code).  You want to pass the equivalent of “-X DELETE” in curl in your Python program.  How do you use the DELETE option with a REST API call in Python?

Solution
Prerequisites

This assumes you have “requests” installed (e.g., sudo pip install requests). 

How Do You Write to a File with Python?

Problem scenario
You want to store variable values in a log file.  How do you get Python to write to a log file?

Solution
Use these lines in your Python program:

var1 = ‘contint’

with open(‘contint.log’, ‘a’) as contint_log:
    contint_log.write(“\n”)  # creates a new line
    contint_log.write(var1)
    contint_log.write(“Done writing variable.\n”) # template text

How Do You Capture Error Messages in a File of Your Choice Using Python Rather Than Have Them Printed to the Screen?

Problem scenario
You have a Python program that displays urllib3 (or some other type) of message to the screen.  You do not want them echoed there cluttering the screen.  You want to redirect the output to a log file (to permanently store the data).  How do you get a Python program to write to a log file?

Solution
Use these three lines, but replace “contint” with the name of your choice:

import logging

logging.basicConfig(filename=’contint.log’,

Why Cannot You Use a Python Module in a Program or the Command Prompt When One Will Work but Not the Other?

Problem scenario
You have a Python program use an import statement, but the program fails.  From the Python command prompt, you can import the module.  Why is it different?

Possible Solution #1
You may be using Python version 3 for either the command prompt or the program and Python version 2 for the complement (either the command prompt or the program). Try these commands:

python –version
python3 –version

Possible Solution #2
See where the potential imports are.