Socket on docker - python

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.

Related

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'

Deploy a VM form ovf, vmdk on a standalone ESXi host without vCenter

I have a single standalone ESXi installation, and it's not being managed by vCenter. How can I programmatically deploy a new VM on this ESXi using an OVF, VMDK file?
I have come across pyvmomi and its deploy_ove.py example, but it looks like it's designed for vCenter.
C:\Users\lab_crbaval\Desktop>python centos_clone\samples\deploy_ovf.py -s 10.24.125.25 -u root -p 1234234 --vmdk-path C:\Users\...centos.vmdk --ovf-path C:\Users\..centos.ovf -nossl
Traceback (most recent call last):
File "centos_clone\samples\deploy_ovf.py", line 143, in <module>
exit(main())
File "centos_clone\samples\deploy_ovf.py", line 118, in main
objs["datacenter"].vmFolder)
File "C:\Python36\lib\site-packages\pyvmomi-7.0.1-py3.6.egg\pyVmomi\VmomiSupport.py", line 706, in <lambda>
File "C:\Python36\lib\site-packages\pyvmomi-7.0.1-py3.6.egg\pyVmomi\VmomiSupport.py", line 511, in _InvokeMethod
File "C:\Python36\lib\site-packages\pyvmomi-7.0.1-py3.6.egg\pyVmomi\VmomiSupport.py", line 1041, in CheckField
TypeError: Required field "spec" not provided (not #optional)
What libraries are available for the automation of a single ESXi host?
You should be able to do it using powercli https://developer.vmware.com/powercli
There is also another tools "ovftools" that I don't know but it should work too https://code.vmware.com/web/tool/4.4.0/ovf
Documentation with example :
https://code.vmware.com/docs/11747/ovf-tool-user-s-guide/GUID-1D091BE1-36D7-42C2-990F-CBBD8F06F51A.html

Getting “pika.exceptions.ConnectionClosed” error while using rabbitmq in python

I am trying to use rabbitmq in python.
My code is:
import pika
if __name__ == '__main__':
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
I am running this file using:
python3 test.py
Error Signature:
Traceback (most recent call last):
File "Test.py", line 4, in <module>
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pika/adapters/blocking_connection.py", line 339, in __init__
self._process_io_for_connection_setup()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pika/adapters/blocking_connection.py", line 374, in _process_io_for_connection_setup
self._open_error_result.is_ready)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pika/adapters/blocking_connection.py", line 395, in _flush_output
raise exceptions.ConnectionClosed()
pika.exceptions.ConnectionClosed
Already referred this , but i dont have any sleep in my code.
Not really sure what could go wrong.
Please let me know if I am missing something obvious.
The issue was with rabbitmqctl. Reconfigured it, Restarted service, and the issue is fixed.
Make sure rabbitmqctl is installed(if installed, uninstall it and re-install;when you just enter rabbitmqctl, it should display the help)
rabbitmqctl start_app
TIP: I tried installing first using 'brew',but for some reason, I was not able to get it right. So installed, rabbitmqctl as a separate package and added to PATH

Connection to AWS timed out using Python boto

I ran Python program in Cygwin to connect to AWS, but failed consistently as being timed out. But my connection to AWS using aws cli in Cygwin always works. Also if I run the same python code in Windows, it also works. I have checked all the connection credentials which are the same for all.
Here is the error msg:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/ec2/connection.py", line 585, in get_all_instances
max_results=max_results)
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/ec2/connection.py", line 681, in get_all_reservations
[('item', Reservation)], verb='POST')
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1170, in get_list
response = self.make_request(action, params, path, verb)
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1116, in make_request
return self._mexe(http_request)
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1030, in _mexe
raise ex
socket.error: [Errno 116] Connection timed out
I have found out that the culprit lies in the proxy credentials.
I put HTTP_PROXY and HTTPS_PROXY as Windows Environment Variables. However, when run in Cygwin, boto uses 'http_proxy' to match without considering the case of the word
(see /boto/connection.py(669)handle_proxy()
line 669: if 'http_proxy' in os.environ and not self.proxy:).
When I changed the capital case HTTP_PROXY to lower case http_proxy, then it worked. Not sure why it isn't a problem if I run with Python in Windows.

Error 500 executing python script

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

Categories

Resources