Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.3 requests issue #1289

Closed
echohack opened this issue Apr 4, 2013 · 67 comments
Closed

Python 3.3 requests issue #1289

echohack opened this issue Apr 4, 2013 · 67 comments

Comments

@echohack
Copy link

echohack commented Apr 4, 2013

I'm getting a strange error when using Requests in Python 3.3 (other flavors of Python 3 do not get this error):

Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 421, in urlopen
    body=body, headers=headers)
  File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 273, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Python33\lib\http\client.py", line 1049, in request
    self._send_request(method, url, body, headers)
  File "C:\Python33\lib\http\client.py", line 1087, in _send_request
    self.endheaders(body)
  File "C:\Python33\lib\http\client.py", line 1045, in endheaders
    self._send_output(message_body)
  File "C:\Python33\lib\http\client.py", line 890, in _send_output
    self.send(msg)
  File "C:\Python33\lib\http\client.py", line 828, in send
    self.connect()
  File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 104, in connect
    ssl_version=resolved_ssl_version)
  File "C:\Python33\lib\site-packages\requests\packages\urllib3\util.py", line 329, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Python33\lib\ssl.py", line 210, in wrap_socket
    _context=self)
  File "C:\Python33\lib\ssl.py", line 310, in __init__
    raise x
  File "C:\Python33\lib\ssl.py", line 306, in __init__
    self.do_handshake()
  File "C:\Python33\lib\ssl.py", line 513, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\requests\adapters.py", line 211, in send
    timeout=timeout
  File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 465, in urlopen
    raise MaxRetryError(self, url, e)
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='analysiscenter.veracode.com', port=443): Max retries exceeded with url: /api/2.0/getappbuilds.do (Caused by <class 'ConnectionResetError'>: [WinError 10054] An existing connection was forcibly closed by the remote host)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\tfs\Vertafore_TFSDev\CQ\python\veracode\pythontestscriptonation.py", line 33, in <module>
    print(v.get_app_builds())
  File "C:\tfs\Vertafore_TFSDev\CQ\python\veracode\apiwrapper.py", line 184, in get_app_builds
    {}
  File "C:\tfs\Vertafore_TFSDev\CQ\python\veracode\apiwrapper.py", line 57, in request
    r = requests.get(URL, params=data, auth=username_password)
  File "C:\Python33\lib\site-packages\requests\api.py", line 55, in get
    return request('get', url, **kwargs)
  File "C:\Python33\lib\site-packages\requests\api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Python33\lib\site-packages\requests\sessions.py", line 354, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python33\lib\site-packages\requests\sessions.py", line 460, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python33\lib\site-packages\requests\adapters.py", line 246, in send
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='analysiscenter.veracode.com', port=443): Max retries exceeded with url: /api/2.0/getappbuilds.do (Caused by <class 'ConnectionResetError'>: [WinError 10054] An existing connection was forcibly closed by the remote host)
[Finished in 61.0s with exit code 1]

This automation has run for months on Python 3.2 and these errors have never occurred. I don't really know enough about requests to investigate this issue, but I'd be happy to help recreate the issue or debug if someone else can. Perhaps there's a bug in how Requests is handling HTTPS requests with Python 3.3? (Did 3.3 change how urllib works?...I don't know offhand...)

Again, I'm not getting any of these issues in Python 3.2 or Python 3.1. Please help! :)

@sigmavirus24
Copy link
Contributor

Please reply with the following: python -c 'import requests; print(requests.__version__)'

@echohack
Copy link
Author

echohack commented Apr 4, 2013

Requests version 1.1.0.

@sigmavirus24
Copy link
Contributor

@t-8ch can explain this in detail but upgrading to 1.2.0 should fix all of your problems.

@echohack
Copy link
Author

echohack commented Apr 4, 2013

Excellent! I'll test it out. Thank you for your quick response. :)

@echohack echohack closed this as completed Apr 4, 2013
@sigmavirus24
Copy link
Contributor

If it doesn't fix it for you, feel free to re-open the issue or ask me to do it for you.

@echohack echohack reopened this Apr 9, 2013
@echohack
Copy link
Author

echohack commented Apr 9, 2013

I'm still having the same failure, no matter where I run it.

C:\Program Files (x86)\Jenkins\jobs\python-test1\workspace>python -V 
Python 3.3.0
C:\Program Files (x86)\Jenkins\jobs\python-test1\workspace>exit 0 
[workspace] $ python C:\Windows\TEMP\hudson581448604896317111.py
Requests Version: 1.2.0
Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 421, in urlopen
    body=body, headers=headers)
  File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 273, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Python33\lib\http\client.py", line 1049, in request
    self._send_request(method, url, body, headers)
  File "C:\Python33\lib\http\client.py", line 1087, in _send_request
    self.endheaders(body)
  File "C:\Python33\lib\http\client.py", line 1045, in endheaders
    self._send_output(message_body)
  File "C:\Python33\lib\http\client.py", line 890, in _send_output
    self.send(msg)
  File "C:\Python33\lib\http\client.py", line 828, in send
    self.connect()
  File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 104, in connect
    ssl_version=resolved_ssl_version)
  File "C:\Python33\lib\site-packages\requests\packages\urllib3\util.py", line 329, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Python33\lib\ssl.py", line 210, in wrap_socket
    _context=self)
  File "C:\Python33\lib\ssl.py", line 310, in __init__
    raise x
  File "C:\Python33\lib\ssl.py", line 306, in __init__
    self.do_handshake()
  File "C:\Python33\lib\ssl.py", line 513, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\requests\adapters.py", line 211, in send
    timeout=timeout
  File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 465, in urlopen
    raise MaxRetryError(self, url, e)
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='analysiscenter.veracode.com', port=443): Max retries exceeded with url: /api/4.0/getapplist.do (Caused by <class 'ConnectionResetError'>: [WinError 10054] An existing connection was forcibly closed by the remote host)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Windows\TEMP\hudson581448604896317111.py", line 11, in <module>
    print(v.get_app_list())
  File "c:/tfs/Vertafore_TFSDev/CQ/python/veracode\apiwrapper.py", line 206, in get_app_list
    {}
  File "c:/tfs/Vertafore_TFSDev/CQ/python/veracode\apiwrapper.py", line 57, in request
    r = requests.get(URL, params=data, auth=username_password)
  File "C:\Python33\lib\site-packages\requests\api.py", line 55, in get
    return request('get', url, **kwargs)
  File "C:\Python33\lib\site-packages\requests\api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Python33\lib\site-packages\requests\sessions.py", line 354, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python33\lib\site-packages\requests\sessions.py", line 460, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python33\lib\site-packages\requests\adapters.py", line 246, in send
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='analysiscenter.veracode.com', port=443): Max retries exceeded with url: /api/4.0/getapplist.do (Caused by <class 'ConnectionResetError'>: [WinError 10054] An existing connection was forcibly closed by the remote host)
Build step 'Execute Python script' marked build as failure
Finished: FAILURE

@t-8ch
Copy link
Contributor

t-8ch commented Apr 11, 2013

Is the URL meant to be publicly accessible?
I get timeouts in every way I try to access it,
so I assume it that the timeout is expected by your testsuite.

On python3.3 the ssl module raises a ConnectionResetError, while on python3.2 it's a socket.error.
Both are wrapped in requests.exceptions.ConnectionError.

Could it be, that your testsuite is somewhere checking the message of the
exception for "socket.error"?

@echohack
Copy link
Author

I was checking for socket.error, however, this isn't the issue (I tested with and without it and it still causes the same failure.) Theoretically, according to PEP 3151, it shouldn't be an issue either, because socket.error is an alias for the new OSError. (right?) http://docs.python.org/dev/whatsnew/3.3.html

Unfortunately this isn't a public API. :(

Based on the error I'm seeing, I'm certain this has to be my code... :|

Thank you so much for your kind help. You guys are really awesome. :)

I hope to have this code open sourced before too long here, so I'll update this thread when that happens. Maybe we can get to the bottom of this...

@PerfectedApp
Copy link

I'm hitting the same problem with Requests 1.2.3 running on Python3.3.

@Lukasa
Copy link
Member

Lukasa commented Jul 22, 2013

@AvivLander Have you tried the solution proposed in #1418?

@PerfectedApp
Copy link

@Lukasa Thanks for the suggested solution. Although, I'm not using SSL in my requests.

@Lukasa
Copy link
Member

Lukasa commented Jul 22, 2013

Really? You're seeing this error without using SSL? I'm not entirely sure that's possible. Can you copy your traceback?

@PerfectedApp
Copy link

@Lukasa, It very well could be an error with the script and not the library. The odd thing here is that the address in question is completely accessible.

Here's a traceback:

Traceback (most recent call last):
  File "test.py", line 212, in <module>
    HTTPtests = requests.get(url + '&skip=' + str(skip) + '&limit=' + str(baseBatch), auth=(username, password), timeout=None)
  File "/usr/local/lib/python3.3/dist-packages/requests-1.2.3-py3.3.egg/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/usr/local/lib/python3.3/dist-packages/requests-1.2.3-py3.3.egg/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.3/dist-packages/requests-1.2.3-py3.3.egg/requests/sessions.py", line 335, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.3/dist-packages/requests-1.2.3-py3.3.egg/requests/sessions.py", line 438, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.3/dist-packages/requests-1.2.3-py3.3.egg/requests/adapters.py", line 327, in send
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='internal-VPC-blablabla.com', port=12345): Max retries exceeded with url: /test/_design/test/_view/test?group_level=2&startkey=[%221%22]&endkey=[%222%22]&skip=5000&limit=500 (Caused by <class 'http.client.BadStatusLine'>: '')

@Lukasa
Copy link
Member

Lukasa commented Jul 22, 2013

So the problem here is right at the end of the exception text: the original exception is http.client.BadStatusLine. Can you either a) make the request from your web browser dev tools and check the status line in the response; or b) do so using Wireshark?

@PerfectedApp
Copy link

So there's actually an error before:

File "/usr/local/lib/python3.3/dist-packages/requests-1.2.3-py3.3.egg
/requests/packages/urllib3/connectionpool.py", line 288, in _make_request
    httplib_response = conn.getresponse(buffering=True)
TypeError: getresponse() got an unexpected keyword argument 'buffering'

@Lukasa
Copy link
Member

Lukasa commented Jul 22, 2013

It should not be possible to hit that error. urllib3 has had a try..except block catching that exception since Requests v0.13.2. Try reinstalling Requests?

@PerfectedApp
Copy link

The issue was related to urllib3 and AWS ELB. It was resolved when routing the request without the ELB. Hardly a desirable option... Regardless, thanks for your help @Lukasa .

"First, ELB has internal "feature" of closing all incoming HTTP connections that do not get response within 60 seconds. I.e. if your client executes GET ... and waits for more then 60 seconds - ELB will close the connection. This timeout is currently unconfigurable through amazon API and even not advertised in Amazon docs. "
http://tech.zarmory.com/2013/02/handling-tmeouts-with-amazon-elastic.html

@Lukasa
Copy link
Member

Lukasa commented Jul 22, 2013

@AvivLander Glad you managed to get to the bottom of this.

@alibitek
Copy link

I still get the TypeError: getresponse() got an unexpected keyword argument 'buffering' for some reason, even though I have Requests 1.2.3 and Python 3.3.1

I have the following stack trace:

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/dist-packages/requests/packages/urllib3/connectionpool.py", line 288, in _make_request
    httplib_response = conn.getresponse(buffering=True)
TypeError: getresponse() got an unexpected keyword argument 'buffering'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/dist-packages/requests/packages/urllib3/connectionpool.py", line 428, in urlopen
    body=body, headers=headers)
  File "/usr/local/lib/python3.3/dist-packages/requests/packages/urllib3/connectionpool.py", line 290, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.3/http/client.py", line 1143, in getresponse
    response.begin()
  File "/usr/lib/python3.3/http/client.py", line 354, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.3/http/client.py", line 316, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.3/socket.py", line 297, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/dist-packages/requests/adapters.py", line 292, in send
    timeout=timeout
  File "/usr/local/lib/python3.3/dist-packages/requests/packages/urllib3/connectionpool.py", line 474, in urlopen
    raise MaxRetryError(self, url, e)
requests.packages.urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='la.wikipedia.org', port=80): Max retries exceeded with url: /w/api.php?bltitle=Britannia+Minor&list=backlinks&action=query&format=json&maxlag=60&blnamespace=0&blredirect=true&bllimit=500 (Caused by <class 'ConnectionResetError'>: [Errno 104] Connection reset by peer)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "remote_coords_finder_5.py", line 185, in <module>
    {'list': 'backlinks', 'bltitle': output['title'], 'blnamespace': 0, 'bllimit': 500, 'blredirect': 'true'}, 'backlinks', 'blcontinue'):
  File "remote_coords_finder_5.py", line 55, in query
    response = requests.get('http://' + language + '.wikipedia.org/w/api.php', params=req, headers=headers, timeout=60)
  File "/usr/local/lib/python3.3/dist-packages/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/usr/local/lib/python3.3/dist-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.3/dist-packages/requests/sessions.py", line 335, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.3/dist-packages/requests/sessions.py", line 438, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.3/dist-packages/requests/adapters.py", line 327, in send
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='la.wikipedia.org', port=80): Max retries exceeded with url: /w/api.php?bltitle=Britannia+Minor&list=backlinks&action=query&format=json&maxlag=60&blnamespace=0&blredirect=true&bllimit=500 (Caused by <class 'ConnectionResetError'>: [Errno 104] Connection reset by peer)

@Lukasa
Copy link
Member

Lukasa commented Aug 22, 2013

@9emE0iL18gxCqLT Are you using AWS ELB?

@alibitek
Copy link

@Lukasa No. Just a locally run Python script that does simple HTTP requests. I'm on a Kubuntu GNU/Linux x86_64 desktop.

@Lukasa
Copy link
Member

Lukasa commented Aug 22, 2013

That's genuinely bizarre. Can you try reinstalling your copy of Requests? (You'll have to delete it first). There's just no way you can hit that exception, because it's inside a try/except block for exactly that purpose.

@alibitek
Copy link

@Lukasa I've reinstalled requests after I deleted it first, and installed it with sudo pip install git+git://github.com/kennethreitz/requests.git . I get exactly the same TypeError, that is:

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/dist-packages/requests/packages/urllib3/connectionpool.py", line 291, in _make_request
    httplib_response = conn.getresponse(buffering=True)
TypeError: getresponse() got an unexpected keyword argument 'buffering'
etc...

@alibitek
Copy link

@Lukasa httplib.HTTPConnection.getresponse() doesn't accept any keyword arguments in Python 3.3

See:

  1. http://docs.python.org/3.3/library/http.client.html?highlight=httpconnection#http.client.HTTPConnection.getresponse
  2. http://hg.python.org/cpython/file/3.3/Lib/http/client.py#l1101

The comments are incorrect in /usr/local/lib/python3.3/dist-packages/requests/packages/urllib3/connectionpool.py line 290:

   try: # Python 2.7+, use buffering of HTTP responses
            httplib_response = conn.getresponse(buffering=True)
        except TypeError: # Python 2.6 and older
            httplib_response = conn.getresponse()

I'll try to send a fix to urllib3.

@Lukasa
Copy link
Member

Lukasa commented Aug 22, 2013

I agree that the comments are incorrect, but the except block should still catch the TypeError, which is why I'm confused. =)

@coagulant
Copy link

but the except block should still catch the TypeError

Well, it is caught, however another exception occurs. For @9emE0iL18gxCqLT it's ConnectionResetError
In my case it's BadStatusLine

Traceback (most recent call last):
  File "/Users/prophet/.envs/djangodash2013/lib/python3.3/site-packages/requests/packages/urllib3/connectionpool.py", line 428, in urlopen
    body=body, headers=headers)
  File "/Users/prophet/.envs/djangodash2013/lib/python3.3/site-packages/requests/packages/urllib3/connectionpool.py", line 290, in _make_request
    httplib_response = conn.getresponse()
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/http/client.py", line 1131, in getresponse
    response.begin()
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/http/client.py", line 354, in begin
    version, status, reason = self._read_status()
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/http/client.py", line 324, in _read_status
    raise BadStatusLine(line)
http.client.BadStatusLine: ''

@Lukasa
Copy link
Member

Lukasa commented Dec 28, 2013

Yeah, maybe. It does make the stack trace so much harder to read, though. =( At least in this case.

@shazow
Copy link
Contributor

shazow commented Dec 28, 2013

Given the popularity of duck-typing in Python, we're going to run into this in all kinds of codebases. Maybe that's a piece of feedback that should go on the Python dev mailing list. :)

@Lukasa
Copy link
Member

Lukasa commented Dec 28, 2013

That's an excellent idea. I'll look through the logs from that list to see if anyone mentioned it.

@mrfatboy
Copy link

I now have the exact same issue with my app on both my windows development and Openshift production servers. I am using Python 3.3 and Requests 2.1. It happens about 30%-50% of the time so it's reasonably reproducible. It seems to happen more when I throw many threaded requests at the target website. I can provide any code to reproduce if you guys need it. Is there a fix on the way? I'm not sure where to go from here. thanks.

@mrfatboy
Copy link

After rereading this thread I see that there are different levels to this problem. I'm thinking I'm throwing to many requests to the target website and they are closing some of the connections causing the ugly exception. Unless anybody has any suggestions I guess I will try to minimize the number of requests at once.

@Lukasa
Copy link
Member

Lukasa commented Jan 17, 2014

@mrfatboy I'm afraid that's all you can do: this is just an artefact of the library design on 3.3.

@juliusakula
Copy link

I'm doing python 3.4.3 and Requests 2.8.0, not using SSL and getting this error. If you're looking how to reproduce this in a test case this happens when I execute a request to a query page which times out after 300 seconds;

this is the SQL query - SELECT SLEEP(500) as id, NOW() as date, CURRENT_USER() limit 1; with this query against a query page (my definition being a server that accepts query as a post variable and executes it returning results, this specific query page has a 5 minute timeout) and I get the error consistently. The remote server is closing the connection after 300 seconds at which point the error is thrown

@Lukasa
Copy link
Member

Lukasa commented Nov 26, 2015

Sorry, @juliusakula, but what exactly is the bug here? Currently it's not clear that we're doing anything wrong: the remote server is closing the connection unexpectedly and we are reporting the event. What you should investigate is why the remote server is closing the connection.

@hwkns
Copy link

hwkns commented Mar 12, 2016

I just ran into this, and I respectfully disagree with the idea that this is a bug in Python rather than requests. Python try/except blocks are meant to be very concise and limited in scope. By placing the entire getresponse() attempt inside an except block, you imply that any exceptions that happen during the course of getresponse() are related to your handling of the TypeError:

# Receive the response from the server
try:
    # For Python 2.7+ versions, use buffering of HTTP
    # responses
    r = low_conn.getresponse(buffering=True)
except TypeError:
    # For compatibility with Python 2.6 versions and back
    r = low_conn.getresponse()

(see: https://github.com/kennethreitz/requests/blob/master/requests/adapters.py#L403-L410)

You could just as easily use:

import sys
# Receive the response from the server
if sys.version_info >= (2, 7):
    # For Python 2.7+ versions, use buffering of HTTP
    # responses
    r = low_conn.getresponse(buffering=True)
else:
    # For compatibility with Python 2.6 versions and back
    r = low_conn.getresponse()

This would prevent the unwanted association of connection errors with an unrelated TypeError. I think it would also reveal that the TypeError occurs more often than anticipated; I can't find any version of the Python docs that says getresponse() takes any arguments, and I know for certain that version 3.5 does not.

@Lukasa
Copy link
Member

Lukasa commented Mar 12, 2016

Using if on sys.version is widely considered bad style in Python, which encourages use of EAFP (Easier To Ask Forgiveness than Permission) as a programming style.

@hwkns
Copy link

hwkns commented Mar 12, 2016

EAFP is indeed encouraged. However, in this case, it is less explicit (thus the need for comments, and the reason no one has noticed those comments are inaccurate), and it causes unrelated error exceptions to be chained to a control flow exception. If EAFP is more important to you than those considerations, that's your call.

@shazow
Copy link
Contributor

shazow commented Mar 12, 2016

The reality is that there are too many cases where doing a version check is simply not sufficient. There are tons of Python platforms and implementations out there—things like Jython, PyPy, AppEngine, eventlet, etc. In fact, many of these platforms are not even stable like CPython might be—a broken feature might be a bug that gets fixed in a minor version bump which is completely incongruent with the CPython reference implementation. Eventually it just seems like it's safest to check if the feature is there and use it if it is, regardless of what version is being advertised.

@hwkns
Copy link

hwkns commented Mar 12, 2016

That is a good point. Are there any versions of Python wherein getresponse() takes arguments? I haven't found any, but if they exist, perhaps something like this could work?

# Receive the response from the server
try:
    r = low_conn.getresponse(buffering=True)
except TypeError:
    r = None
if r is None:
    r = low_conn.getresponse()

I'll admit, it looks a bit confusing...

@sigmavirus24
Copy link
Contributor

@hwkns apparently it's undocumented, but Python 2 accepted buffering: https://hg.python.org/cpython/file/2.7/Lib/httplib.py#l1099

@sandeepnassa
Copy link

I am bit new to Python. From python i am calling some Jira APIs, those were working fine for a month but suddenly started throwing error for connection aborted

Using python 2.7.0. any suggestion please? Struggling for long

Traceback (most recent call last):
File "jiraTestCasesExecution.py", line 1091, in
main(sys.argv[1:])
File "jiraTestCasesExecution.py", line 1083, in main
test_cycle_execution()
File "jiraTestCasesExecution.py", line 941, in test_cycle_execution
do_update_test_case_in_jira(os.environ['EnvJiraId'], testCaseStatus["Status"], summary, description)
File "jiraTestCasesExecution.py", line 608, in do_update_test_case_in_jira
updateResponse = requests.put(updateTestStatusURL, json=updateParams, headers=headers)
File "C:\Python27\lib\site-packages\requests\api.py", line 122, in put
return request('put', url, data=data, *_kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 50, in request
response = session.request(method=method, url=url, *_kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 465, in request
resp = self.send(prep, *_send_kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 573, in send
r = adapter.send(request, *_kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 415, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(10054, 'An existing connection was forcibly closed by the remote host'))

@hwkns
Copy link

hwkns commented Apr 26, 2016

@sandeepnassa sorry, but this isn't the appropriate place to ask for help with that. Also, when you do find the right place, no one will be able to tell you why the Jira API is closing your connection without seeing your code.

@sandeepnassa
Copy link

Thank you @daniel Hawkins for response.

My concern is not about Jira API.. its about the same connection aborted issue error 10054.. we are discussing in this thread.
requests.exceptions.ConnectionError: ('Connection aborted.', error(10054, 'An existing connection was forcibly closed by the remote host'))

through python i am calling those APIs.

i can provide code if required

@Lukasa
Copy link
Member

Lukasa commented Apr 26, 2016

@sandeepnassa That exception is caused by the machine hosting the URL you're using forcibly tearing the connection down. It is very hard to work out why that would be happening without extremely large amounts of detail. However, if they've been working fine for a month: did you update JIRA? They may have changed their API.

@sandeepnassa
Copy link

Thanks @Lukasa for response
I check with Jira API, they are in denial that they have changed anything about those apis.
I want to double check from my side that it Is nothing related to python (which is owned by me), there is no setting in python which I should use to correct this.. Before I can ask Jira guys again firmly that everything Is correct from my side.

So was looking for expert knowledge.

BTW.. this is the header I am using to call those Jira restful APIs

@Lukasa
Copy link
Member

Lukasa commented Apr 26, 2016

Do you have logs from the JIRA server? Those logs may tell you what's going on.

To be clear, it's entirely possible that it is in your code, but it's extremely unlikely that requests is doing this wrong.

@zbyte64
Copy link

zbyte64 commented May 15, 2016

Instead of doing a try except you could instead inspect.getargspec and check if the function actually accepts a buffering keyword argument.

@sigmavirus24
Copy link
Contributor

@zbyte64 except that doesn't work consistently across all versions of Python 3. 3.5 for example doesn't allow that to work as easily

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests