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

SSL3_GET_RECORD:wrong version number exception during requests to Google Analytics API #37

Closed
jessepollak opened this issue Nov 12, 2014 · 13 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@jessepollak
Copy link

When using the client to make requests to the Google Analytics, API, we see the following exception occasionally. It can usually be solved by making retrying the request.

...
    data = service.data().ga().get(*args, **kwargs).execute(num_retries=3)
  File "/Users/jessepollak/.virtualenvs/clef/lib/python2.7/site-packages/oauth2client/util.py", line 129, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Users/jessepollak/.virtualenvs/clef/lib/python2.7/site-packages/googleapiclient/http.py", line 716, in execute
    body=self.body, headers=self.headers)
  File "/Users/jessepollak/.virtualenvs/clef/lib/python2.7/site-packages/oauth2client/util.py", line 129, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Users/jessepollak/.virtualenvs/clef/lib/python2.7/site-packages/oauth2client/client.py", line 533, in new_request
    redirections, connection_type)
  File "/Users/jessepollak/.virtualenvs/clef/lib/python2.7/site-packages/httplib2/__init__.py", line 1570, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/Users/jessepollak/.virtualenvs/clef/lib/python2.7/site-packages/httplib2/__init__.py", line 1317, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/Users/jessepollak/.virtualenvs/clef/lib/python2.7/site-packages/httplib2/__init__.py", line 1286, in _conn_request
    response = conn.getresponse()
  File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1045, in getresponse
    response.begin()
  File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 409, in begin
    version, status, reason = self._read_status()
  File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 365, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)
  File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 241, in recv
    return self.read(buflen)
  File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 160, in read
    return self._sslobj.read(len)
SSLError: [Errno 1] _ssl.c:1426: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number
@craigcitro
Copy link
Contributor

yeah, it's just some communication badness happening under the hood -- not much we can do at this level other than just retry (as you're doing).

@jessepollak
Copy link
Author

Are you sure this has nothing to do with disabling SSL_V3?

Any chance we could move this into the library so future users don't waste time attempting to debug — happy to investigate a PR.

@dhermes
Copy link
Contributor

dhermes commented Dec 17, 2015

@jessepollak Were you by any chance using the same httplib2.Http instance in multiple threads?

@jessepollak
Copy link
Author

Not explicitly, but it could have been happening under the hood?

@dhermes
Copy link
Contributor

dhermes commented Dec 17, 2015

For sure. For example if you created a service with build you get an instance of httplib2.Http bound to the service.

You can confirm, at least, that you were using google-api-python-client with threaded code?

@jessepollak
Copy link
Author

Hm, so we are using it inside of Flask, which I'm pretty sure spins up multiple threads (at least in local environments), so yes.

@dhermes
Copy link
Contributor

dhermes commented Dec 17, 2015

Somewhat "confirms" what our other experience indicates.

If you're still having this issue, check out:
https://developers.google.com/api-client-library/python/guide/thread_safety

It'll increase the memory consumption a teensy bit (i.e. just by the size of one instance) but you won't have these issues where one thread eats the bytes intended for another.

@jessepollak
Copy link
Author

Cool, thank you for the response!!

@dhermes
Copy link
Contributor

dhermes commented Dec 17, 2015

Sure thing. Before we knew what was causing the error I collected lots of similar bugs on the web (including this one). I figured since this helped confirm it was a real issue, I should give back a little bit.

@jessepollak
Copy link
Author

👍

@naoko
Copy link

naoko commented Aug 11, 2016

Thank you for the solution @dhermes and thank you for posting this issue @jessepollak .
I didn't notice this error until I run load testing and instantiating Http on every request in fact fixed the issue.

@aj07mm
Copy link

aj07mm commented Jan 14, 2019

I was having the same problem. What was happening is that I had 2 connections one in two different scopes, try to use it as a singleton and see if it works.

akrherz pushed a commit to akrherz/google-api-python-client that referenced this issue Apr 1, 2019
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 6, 2020
@sakibstark11
Copy link

@jessepollak Were you by any chance using the same httplib2.Http instance in multiple threads?

I was having similar issue when working with google apis in threads. Turns out, I had to build individual services for each threads. Thanks so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

7 participants