IMAP4_SSL: EOF occurred in violation of protocol - python

I'm not great with Python but I've inherited a script (from a former co-worker) that is giving the above error. Here's the traceback:
File "/abackup/rob/python/mail/one_and_one/__init__.py", line 119, in open
mailbox = imaplib.IMAP4_SSL(self.host, self.port)
File "/usr/local/lib/python2.6/imaplib.py", line 1137, in __init__
IMAP4.__init__(self, host, port)
File "/usr/local/lib/python2.6/imaplib.py", line 163, in __init__
self.open(host, port)
File "/usr/local/lib/python2.6/imaplib.py", line 1150, in open
self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
File "/usr/local/lib/python2.6/ssl.py", line 350, in wrap_socket
suppress_ragged_eofs=suppress_ragged_eofs)
File "/usr/local/lib/python2.6/ssl.py", line 118, in __init__
self.do_handshake()
File "/usr/local/lib/python2.6/ssl.py", line 293, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [Errno 8] _ssl.c:480: EOF occurred in violation of protocol
As far as I know, this was working a month ago. I have tried Googling and looked at the only other thread of stackoverflow that references this, but it doesn't seem to apply... the error seems to be occurring within the library, since all I'm calling is the constructor with a valid hostname and port.

It looks like this is related to our firewall or something... which I of course have no control over... sigh...

Related

ConnectionResetError while running through cron

I'm sending a simple 'post' request through the 'requests' module. It works fine when execute it directly through the linux terminal. However, when I set it up through the crontab, the log is indicating and error.
If I execute the below through the terminal, it works fine.
'/usr/bin/python3.6 /location/sa/tb/uc/md/se/sea.py'
If I setup the crontab as follows, I get an error.
/usr/bin/python3.6 /location/sa/tb/uc/md/se/sea.py >> ~/Test_log.log 2>&1
Below is the error message:
File
"/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py",
line 600, in urlopen
chunked=chunked) File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py",
line 343, in _make_request
self._validate_conn(conn) File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py",
line 839, in validate_conn
conn.connect() File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line
344, in connect
ssl_context=context) File "/usr/local/lib/python3.6/site-packages/urllib3/util/ssl.py", line
345, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname) File "/usr/lib64/python3.6/ssl.py", line 365, in wrap_socket
_context=self, _session=session) File "/usr/lib64/python3.6/ssl.py", line 776, in init
self.do_handshake() File "/usr/lib64/python3.6/ssl.py", line 1036, in do_handshake
self._sslobj.do_handshake() File "/usr/lib64/python3.6/ssl.py", line 648, in do_handshake
self._sslobj.do_handshake() ConnectionResetError: [Errno 104] Connection reset by peer
What did I try?
Tried adding absolute path inside the script.
Added a proxy to the headers, but no go.
Any help would be appreciated.
Some servers don't start re-listen immediately (check_mk flag), while calling multiple requests from a single connection. One of the reason is to avoid DoS attacks and service availability to all users.
Since your crontab made your script to call the same API multiple times using a single connection, I'd suggest you to add a void timer before making a request, e.g. add time.sleep(0.01) just before calling the API.

How can I globally set the SSL protocol for a python application?

I'm working on maintaining a Python application for my company that uses pysphere to connect to a vCenter. If our users select the option to only allow incoming requests via TLSv1 (default is both TLSv1 and SSLv3, and the setting is rarely changed) then we see the following stacktrace:
2015-05-08 13:19:38,000 vcenterutils 72 Encountered exception Errno 8 _ssl.c:504: EOF occurred in violation of protocol at Traceback (most recent call last):
File "vcenterutils.pyo", line 68, in run
File "vcenterutils.pyo", line 127, in connect
File "vcenterutils.pyo", line 140, in login
File "pysphere\vi_server.pyo", line 101, in connect
File "pysphere\resources\VimService_services.pyo", line 2170, in RetrieveServiceContent
File "pysphere\ZSI\client.pyo", line 295, in Send
File "httplib.pyo", line 1161, in connect
File "ssl.pyo", line 381, in wrap_socket
File "ssl.pyo", line 143, in _init
File "ssl.pyo", line 305, in do_handshake
SSLError: Errno 8 _ssl.c:504: EOF occurred in violation of protocol
This leads me to believe that there is some explicit usage of SSLv3 in the code. Is there a way to override this as a global default so ssl.PROTOCOL_SSLv23 is always used?

My python script that i had tested and was working fine. Suddenly starts getting connection error

I wrote a few lines of python script to get links from my small site. I tested it, used it and was working fine but suddenly it starts generating connection error. I tried to use it on another site, it still generate same problem. I'm new to python, though. Help please!!! Thanks in advance
Part of the code and error message is as follow:
>>>import urllib,sgmllib
>>> f=urllib.urlopen("http://www.example.com")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\urllib.py", line 87, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 208, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 345, in open_http
h.endheaders(data)
File "C:\Python27\lib\httplib.py", line 991, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 844, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 806, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 787, in connect
self.timeout, self.source_address)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
IOError: [Errno socket error] [Errno 10061] No connection could be made becausethe target machine actively refused it
>>>
Thank you Johan, Shashank, bmhkim for your contributions.
I just figured out the cause of the problem now and the solution. It was caused by the proxy setting of the host running the code. So, resetting the proxy solve it.

error: [Errno 32] Broken pipe when paypal calls back to python django app

Hi I am doing papal integration with my django app.
i am using latest version of django from svn and python 2.6.
However, i found every time when paypal's sandbox accessing my notify url i got 500 [Errno 32] Broken pipe my django stack.
Does anyone have similar experience with this ?
Cheers,
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 281, in run
self.finish_response()
File "/usr/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 321, in finish_response
self.write(data)
File "/usr/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 417, in write
self._write(data)
File "/usr/lib/python2.6/socket.py", line 318, in write
self.flush()
File "/usr/lib/python2.6/socket.py", line 297, in flush
self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 104] Connection reset by peer
----------------------------------------
Exception happened during processing of request from ('216.113.191.33', 21736)
Traceback (most recent call last):
File "/usr/lib/python2.6/SocketServer.py", line 283, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.6/SocketServer.py", line 309, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.6/SocketServer.py", line 322, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 562, in __init__
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
File "/usr/lib/python2.6/SocketServer.py", line 618, in __init__
self.finish()
File "/usr/lib/python2.6/SocketServer.py", line 661, in finish
self.wfile.flush()
File "/usr/lib/python2.6/socket.py", line 297, in flush
self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 32] Broken pipe
----------------------------------------
The first error Connection reset by peer show you that the connection have been closed by peer (in your case Pypal) and for the Error Broken pipe this error is raised when a connection is closed suddenly without informing the other peer (in your case your machine).
There are two problems. First, some of the paypal APIs (particularly MassPay) are terribly poor.
The second, and more likely, problem, is that your server is single-threaded and is having trouble properly raising an exception to paypal. I was able to resolve a similar problem by creating an html file with a form (via POST) that mocked a paypal IPN and then looking at the debug result (or better, using a debugger like the one in PyDev). You could do the same thing with curl of course.

Problem with python urllib

I'm getting an error when ever I try to pull down a web page with urllib.urlopen. I've disabled windows firewall and my AV so its not that. I can access the pages in my browser. I even reinstalled python to rule out it being a broken urllib. Any help would be greatly appreciated.
>>> import urllib
>>> h = urllib.urlopen("http://www.google.com").read()
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
h = urllib.urlopen("http://www.google.com").read()
File "C:\Python26\lib\urllib.py", line 86, in urlopen
return opener.open(url)
File "C:\Python26\lib\urllib.py", line 205, in open
return getattr(self, name)(url)
File "C:\Python26\lib\urllib.py", line 344, in open_http
h.endheaders()
File "C:\Python26\lib\httplib.py", line 904, in endheaders
self._send_output()
File "C:\Python26\lib\httplib.py", line 776, in _send_output
self.send(msg)
File "C:\Python26\lib\httplib.py", line 735, in send
self.connect()
File "C:\Python26\lib\httplib.py", line 716, in connect
self.timeout)
File "C:\Python26\lib\socket.py", line 514, in create_connection
raise error, msg
IOError: [Errno socket error] [Errno 10061] No connection could be made because the target machine actively refused it
>>>
this could be the case:
Just found the problem I had set a
proxy through internet options, that
proxy went offline, and so did my
python shell.
urllib is working just fine.
Try using ethereal (or some similar network sniffer) on your box to determine if the denial coming from your machine or a machine beyond.

Categories