Error 500 executing python script - python

I recently re-installed my Ubuntu PC (to 12.04) & had to re-setup apache.
local.domain.com points to localhost (virtual host).
http://local.domain.com/script.py?query=string
script.py is chmod'd to 755.
In my .htaccess I have :
Options +ExecCGI
AddHandler cgi-script .py
But I get a 500 : Internal Server Error.
cat /var/log/apache2/error.domain.com.log shows nothing.
If I do python script.py in the command line I get :
<!-- The above is a description of an error in a Python program, formatted
for a Web browser because the 'cgitb' module was enabled. In case you
are not reading this in a Web browser, here is the original traceback:
Traceback (most recent call last):
File "script.py", line 32, in <module>
queryHash = hashlib.sha224(os.environ['QUERY_STRING']).hexdigest()
File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'QUERY_STRING'
-->
So I don't figure anything wrong with the py script. It used to work before.
But for some reason its not executing in the browser.
What else could I have missed ?

The error is right there infront of you:
Traceback (most recent call last):
File "script.py", line 32, in <module>
queryHash = hashlib.sha224(os.environ['QUERY_STRING']).hexdigest()
File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'QUERY_STRING'
Which says it can't access the key QUERY_STRING. It even gives you the exact line of code that the error occurred at:
File "script.py", line 32
queryHash = hashlib.sha224(os.environ['QUERY_STRING']).hexdigest()
The environment variable QUERY_STRING has not been set for the apache user. How did you have this set before? You might need to set it in the httpd profile, and for Ubuntu, I'm not sure where that is.

Ubuntu 12.04 has python 2.7. My script's shebang line was :
#!/usr/bin/env python2.6

Related

Socket on docker

I have written 3 pyhton script working on local and connected with socket.
I want to create docker containers for each script (one script = one container). But when I lauch the first one (just listenning on socket) i have this error :
JOB START
Traceback (most recent call last):
File "/demo/classifier.py", line 35, in <module>
socket.connect("tcp://%s:%s" % (config["SOCKET"]["Hostname"], config["SOCKET"]["PortDetection"]))
File "/opt/conda/lib/python3.9/configparser.py", line 963, in __getitem__
raise KeyError(key)
KeyError: 'SOCKET'
I haven't the right on the config file so I need to do chmod 777 on /config.ini
And now when I run my code, it find the config file with "Socket" in.

os.environ producing error recently only?

Recently I had this problem with vscode where os.environ isn't working anymore, it used to be able to read the key on the separate .env file. This file works perfect on replit, however, when i try downloading it, it can't be run locally
I have tried deleting .pyc files, but it's still the same.
Python os.environ throws key error?
Error in the terminal:
Traceback (most recent call last):
File "c:\Users\heroku\Desktop\ricebot\main.py", line 62, in <module>
my_secret = os.environ['TOKEN']
File "C:\Users\heroku\AppData\Local\Programs\Python\Python39\lib\os.py", line 679, in __getitem__
raise KeyError(key) from None
KeyError: 'TOKEN'

Curses app throws _curses.error: init_pair() returned ERR

I have a problem whenever i run my curses application,it always runs fine on windows(thanks to windows-curses module) and other Linux Distros,but since i have Garuda Linux installed i want to run the app on it.but the problem is,whenever i run the app it yields the following error:
Traceback (most recent call last):
File "/home/justaus3r/Desktop/Programming/Python/Projects/ANFU/Anfu.py", line 564, in <module>
curses.wrapper(Main)
File "/usr/lib/python3.9/curses/__init__.py", line 94, in wrapper
return func(stdscr, *args, **kwds)
File "/home/justaus3r/Desktop/Programming/Python/Projects/ANFU/Anfu.py", line 330, in Main
curses.init_pair(69, curses.COLOR_MAGENTA, -1)
_curses.error: init_pair() returned ERR
i have tried it with different terminals like xterm and Alacritty.it throws the same error,does my code has some problems or the module isn't compatible with Garuda Linux.any help is appreciated
I was gettiing same issue in redhat - maipo
this worked for me
export TERM=xterm-256color

File not found error, but file exists

I am working on a simple webapp from Head First Python. I am using ubuntu 14.04. But it is the error:
Traceback (most recent call last):
File "/usr/lib/python3.4/http/server.py", line 1143, in run_cgi
os.execve(scriptfile, args, env)
FileNotFoundError: [Errno 2] No such file or directory:
'/home/sarthak/Desktop/Learn/HeadFirstPython/chapter7/webapp/cgi-bin/generate_list.py'
127.0.0.1 - - [12/Jun/2015 07:08:25] CGI script exit status 0x7f00
The file surely exists on the system and it is made executable.
How to fix the problem?
The Problem lies in the 'wrong' path of the shebang line (the first line which says #!/usr/local/bin/python3) of the generate_list.py file.
If you are using ubuntu the location of python3 is probably /usr/bin/python3 (You can find out your python3 location by typing which python3 into the shell/terminal). So you have to adjust the first line to the actual address of python3 in order to make your script work.

Error using Elaphe with GhostScript on Mac

I'm trying to setup elaphe on Mac. When I try generate some barcode using the terminal, with command python + /.../file.py elaphe works OK and generates the barcode correctly. But when I try to execute through web (php) I get the following error in the Apache's error logs:
Traceback (most recent call last):
File "lib/barcode_generator/generator.py", line 19, in <module>
code_39_image.save(str(random)+'.tif')
File "/Users/x/Library/Python/2.7/lib/python/site-packages/PIL/Image.py", line 1406, in save
self.load()
File "/Users/x/Library/Python/2.7/lib/python/site-packages/PIL/EpsImagePlugin.py", line 283, in load
self.im = Ghostscript(self.tile, self.size, self.fp)
**File "/Users/x/Library/Python/2.7/lib/python/site-packages/PIL/EpsImagePlugin.py", line 72, in Ghostscript
gs.write(s)**
If I were in Windows I would say it is a problem with the path and the program can't find the "gs.write" but in Mac I'm a rookie, I don't know if it's the same, nevertheless I've already include this 2 path:
export PATH=/Users/x/Library/Python/2.7/bin:$PATH
export PATH=/usr/local/bin:$PATH
I would appreciate can give some ideas regarding this error.
Thanks in advance.
Fixed via a symbolic link. Clearly was a PATH issue or hardcoded reference to the gs binary.
sudo ln -s /usr/local/bin/gs /usr/bin/gs

Categories

Resources