Python EOFError after using os.execl to restart the script - python

I have a script that does the following;
Checks if a temp.txt file is present in the working directory.
If present the temp.txt file and update.pyd file is removed.
Checks whether an update.pyd module is present in the working directory.
If present it imports and runs it.
The update process creates a temp.txt file in the working directory.
After the update the script is restarted using os.execl(sys.executable, sys.executable, *sys.argv)
But I keep getting an error when os.execl(sys.executable, sys.executable, *sys.argv) is called:
Traceback (most recent call last):
File "<string>", line 73, in execInThread
File "<string>", line 44, in __call__
File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py", line 196, in __call__
File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py", line 71, in syncreq
File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 431, in sync_request
File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 379, in serve
File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 337, in _recv
File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\channel.py", line 50, in recv
File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\stream.py", line 166, in read
EOFError: [WinError 10054] An existing connection was forcibly closed by the remote host
I have another process in the same script that does something similar, and restarts using os.execl(sys.executable, sys.executable, *sys.argv), but restarts cleanly.
Could someone tell me why this is happening. What "connection" is the error referring to, and how do I close it before restarting? Thanks

Related

Pyinstaller "FileNotFoundError: [Errno 2] No such file or directory:" when running app

I recently have packaged a python app using the pyinstaller --onefile command. It succesfully makes a executable file that launches fine. I can use pretty much almost all the functions in my script with no problem, except one. When I call a function of another python file (which is in my app folder), I get this error:
Traceback (most recent call last):
File "socketserver.py", line 647, in process_request_thread
File "socketserver.py", line 357, in finish_request
File "socketserver.py", line 717, in __init__
File "http/server.py", line 426, in handle
File "http/server.py", line 414, in handle_one_request
File "CaptchaHarvester/harvester/server/__init__.py", line 134, in do_GET
File "CaptchaHarvester/harvester/server/__init__.py", line 178, in handel_request
File "CaptchaHarvester/harvester/server/__init__.py", line 85, in _load_template
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/rl/rmr5s0ld22j0h_z15m90v0c80000gr/T/_MEIBVnHEv/harvester/server/templates/ga.chunk.html'
----------------------------------------
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 54955)
Traceback (most recent call last):
File "socketserver.py", line 647, in process_request_thread
File "socketserver.py", line 357, in finish_request
File "socketserver.py", line 717, in __init__
File "http/server.py", line 426, in handle
File "http/server.py", line 414, in handle_one_request
File "CaptchaHarvester/harvester/server/__init__.py", line 122, in do_GET
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/rl/rmr5s0ld22j0h_z15m90v0c80000gr/T/_MEIBVnHEv/harvester/server/icon.png'
The problem seems to be that pyinstaller cant properly find the files(icon.png and ga.hunk.html). These files are in a folder that is in the same folder as my main.py file. I was wondering how I can make pyinstaller find these files succesfully? I have tried to add to the datas class in the .spec file, but I still get the error. This is what that line looks like:datas=[('/Users/A/Desktop/ss/CaptchaHarvester/harvester/server/icon.png','/Users/A/Desktop/ss/CaptchaHarvester/harvester/server')],
Please let me know if I am doing something wrong or if yall have any ideas on how to resolve it.
I am on macosx catalina and python 3.7 if that is any help.
Thanks!
You can use arguments in command prompt to ensure the correct filesare found by pyinstaller; --add-data "path_to_file:path_in_executable in directory" an example would be
pyinstaller --add-data "icon.png;." --onefile socketserver.py
here icon.png is in the same directoy of socketserver.py and is copied to the root directory of the executable (the . signifies root directory)

Django ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

I am using django with postgresql, whenever I try to save or delete anything, this error occurs -
Traceback (most recent call last):
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
Not Found: /favicon.ico
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 255, in send_preamble
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
[02/Aug/2016 18:30:14] "GET /favicon.ico HTTP/1.1" 404 2044
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 453, in _write
self.stdout.write(data)
File "c:\program files (x86)\python35-32\Lib\socket.py", line 593, in write
return self._sock.send(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
[02/Aug/2016 18:30:14] "GET /api/delete/ HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 1712)
Traceback (most recent call last):
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 255, in send_preamble
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 453, in _write
self.stdout.write(data)
File "c:\program files (x86)\python35-32\Lib\socket.py", line 593, in write
return self._sock.send(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 141, in run
self.handle_error()
File "C:\Users\sushant\Desktop\projects\drfapi\venv\lib\site-packages\django\core\servers\basehttp.py", line 92, in handle_error
super(ServerHandler, self).handle_error()
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 368, in handle_error
self.finish_response()
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\program files (x86)\python35-32\Lib\socketserver.py", line 628, in process_request_thread
self.finish_request(request, client_address)
File "c:\program files (x86)\python35-32\Lib\socketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\sushant\Desktop\projects\drfapi\venv\lib\site-packages\django\core\servers\basehttp.py", line 99, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "c:\program files (x86)\python35-32\Lib\socketserver.py", line 684, in __init__
self.handle()
File "C:\Users\sushant\Desktop\projects\drfapi\venv\lib\site-packages\django\core\servers\basehttp.py", line 179, in handle
handler.run(self.server.get_app())
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 144, in run
self.close()
File "c:\program files (x86)\python35-32\Lib\wsgiref\simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
What happens is whenever a database save\delete command is there, it gets executed twice, first time without errors, second time, throwing this error and hence, save is done twice.
What I understand is some program is blocking it(as the error says) so I removed the anti-virus that I had but with no conclusions.
Does anyone have any idea what this is all about?
Edit: It's a Python bug, reported here
I have checked in a fix for this in Python: https://github.com/python/cpython/pull/9713
It will be available in the next version of Python 3.7 and later.
I was making a web application and was facing the same issue in windows 10, python 3.7.6, django 3.0.8. I tried a lot of stuff and i finally found a fix.
I was using a form which called a js function onsubmit which in turn sent a REST call which was getting canceled with the '[WinError 10053] An established connection was aborted by the software in your host machine' error in command prompt.
I added the parameter method='post' and used jQuery.ajax in the js function and i added the event.preventDefault() as well in the function as well as some success and fail callbacks. I don't understand why but now i am not getting the error.
Hope this help anyone using js along with HTML forms until a the issue is root-caused and fixed.
This Github bug is tracking the issue
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
If you are working with the videos this happens when you make another request while the video is uploading to the database.
I would suggest you to use preload='none' in video tag or block the new requests while video is uploading.
I was running into this error even with Python 3.6.5 and django 2.0
I noticed 301 redirects in the network tab of the browser debugger. When I fixed them by appending trailing backslashes to all url/api calls in my html/js, this problem went away. The urlconf must have trailing backslashes as well.
this happened to me in the past:
In my case:
I opened it in firefox first and faced this error.
then I opened it in Microsoft edge and the error was gone.
try this:
open the server URL in a different browser, and see the result must be normal.
I had the same error: ConnectionAbortedError: [WinError 10053].
Python version: 3.8.1
I restarted my computer and the error disappeared

Development Server Load Error

I wasn't able to load my app engine development server due to an error without a log file. After re-installing it and deleting the .ini files, I got the launcher to launch.
However, one out of my three projects will now not launch, with a trace that doesn't make much sense (it refers to pickle when I don't use it anywhere in my project). If you can give me any help it would be appreciated.
Trace:
2016-05-15 22:45:02 Running command: "['C:\\Python27\\pythonw.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=4712', '--admin_port=8000', 'C:\\Users\\Paul\\Desktop\\Tram Live\\App Engine\\Sheffield']"
INFO 2016-05-15 22:45:05,448 devappserver2.py:769] Skipping SDK update check.
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 84, in <module>
_run_file(__file__, globals())
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 80, in _run_file
execfile(_PATHS.script_file(script_name), globals_)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 1040, in <module>
main()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 1033, in main
dev_server.start(options)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 820, in start
request_data, storage_path, options, configuration)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 925, in _create_api_server
appidentity_oauth_url=options.appidentity_oauth_url)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\api_server.py", line 477, in setup_stubs
simple_search_stub.SearchServiceStub(index_file=search_index_path))
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\search\simple_search_stub.py", line 683, in __init__
self.Read()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\search\simple_search_stub.py", line 1164, in Read
read_indexes = self._ReadFromFile()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\search\simple_search_stub.py", line 1138, in _ReadFromFile
version, indexes = pickle.load(open(self.__index_file, 'rb'))
EOFError
2016-05-15 22:45:05 (Process exited with code 1)

Google AppEngine Python OSError "too many files open" at launch

I'm using ubuntu 13.10 running in a VM on OSX, python2.7 and GAE 1.8.8.
Lauching dev_appserver.py results in the following error:
INFO 2013-12-10 03:53:30,046 api_server.py:527] Saving search indexes
Traceback (most recent call last):
File "/home/ubuntu/xxxxxx/google_appengine/dev_appserver.py", line 197, in <module>
File "/home/ubuntu/xxxxxx/google_appengine/dev_appserver.py", line 193, in _run_file
File "/home/ubuntu/xxxxxx/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 872, in <module>
File "/home/ubuntu/xxxxxx/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 868, in main
File "/home/ubuntu/xxxxxx/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 707, in stop
File "/home/ubuntu/xxxxxx/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 141, in quit
File "/home/ubuntu/xxxxxx/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 528, in cleanup_stubs
File "/home/ubuntu/xxxxxx/google_appengine/google/appengine/api/search/simple_search_stub.py", line 984, in Write
File "/usr/lib/python2.7/tempfile.py", line 304, in mkstemp
File "/usr/lib/python2.7/tempfile.py", line 239, in _mkstemp_inner
OSError: [Errno 24] Too many open files: '/tmp/appengine.xxxxxx-hr-dev.ubuntu/tmpMVVXrH'
Any ideas?
Check the shared memory parameter, kern.sysv.shmseg on your linux system and set it right by increasing it.
To view the shared memory parameters, use:
sysctl -A | grep shm
To update that parameters, edit file:
sudo nano /etc/sysctl.conf
Refer to this SO answer for more information.

Python App Engine will not deploy - timeout

My app refuses to deploy, just writes
Checking if deployment succeeded.
Will check again in 60 seconds.
Over and over, then times out.
This is my .bat file:
python "C:\Program Files (x86)\Google\google_appengine\appcfg.py"
--email=my email --passin update "app directory"
My internet connection works ok otherwise. Any ideas?
Full error:
2013-02-02 21:01:22,963 WARNING appcfg.py:2053 Version still not ready to serve,
aborting.
2013-02-02 21:01:22,966 ERROR appcfg.py:2267 An unexpected error occurred. Abort
ing.
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\ap
pcfg.py", line 2253, in DoUpload
app_summary = self.Commit()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\ap
pcfg.py", line 2054, in Commit
raise Exception('Version not ready.')
Exception: Version not ready.
09:01 PM Rolling back the update.
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\appcfg.py", line 171, in
<module>
run_file(__file__, globals())
File "C:\Program Files (x86)\Google\google_appengine\appcfg.py", line 167, in
run_file
execfile(script_path, globals_)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\ap
pcfg.py", line 4377, in <module>
main(sys.argv)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\ap
pcfg.py", line 4368, in main
result = AppCfgApp(argv).Run()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\ap
pcfg.py", line 2605, in Run
self.action(self)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\ap
pcfg.py", line 4103, in __call__
return method()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\ap
pcfg.py", line 3115, in Update
self.UpdateVersion(rpcserver, self.basepath, appyaml)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\ap
pcfg.py", line 3097, in UpdateVersion
return appversion.DoUpload(paths, openfunc)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\ap
pcfg.py", line 2253, in DoUpload
app_summary = self.Commit()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\ap
pcfg.py", line 2054, in Commit
raise Exception('Version not ready.')
Exception: Version not ready.
I don't think that you're doing anything wrong. Sometimes Google App Engine is not responding the way you want, because they might have some issues on their side.
Try to change a version and redeploy (or use the --version=version-name in the command line). If that is not going to fix it, you'll have to wait a while and then try again

Categories

Resources