proxy - Got requests.exceptions.SSLError error when running googleplay-api

05
2014-04
  • Wu Yongzheng

    I want to share my experience on the problem, so this is sort of a self-answered question. Hope it helps.

    I'm trying to use googleplay-api to download apks from Google Play. My network environment forces me to use a web proxy. I got the following error when running python search.py earth:

    $ python search.py earth
    Traceback (most recent call last):
      File "search.py", line 30, in <module>
        api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN)
      File "/home/atp/build/googleplay-api/googleplay.py", line 125, in login
        response = requests.post(self.URL_LOGIN, data=params, headers=headers, verify=False)
      File "/usr/lib/python2.7/site-packages/requests/api.py", line 88, in post
        return request('post', url, data=data, **kwargs)
      File "/usr/lib/python2.7/site-packages/requests/api.py", line 44, in request
        return session.request(method=method, url=url, **kwargs)
      File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 335, in request
        resp = self.send(prep, **send_kwargs)
      File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 438, in send
        r = adapter.send(request, **kwargs)
      File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 331, in send
        raise SSLError(e)
    requests.exceptions.SSLError: hostname 'android.clients.google.com' doesn't match either of '*.google.com', '*.android.com', '*.appengine.google.com', '*.cloud.google.com', '*.google-analytics.com', '*.google.ca', '*.google.cl', '*.google.co.in', '*.google.co.jp', '*.google.co.uk', '*.google.com.ar', '*.google.com.au', '*.google.com.br', '*.google.com.co', '*.google.com.mx', '*.google.com.tr', '*.google.com.vn', '*.google.de', '*.google.es', '*.google.fr', '*.google.hu', '*.google.it', '*.google.nl', '*.google.pl', '*.google.pt', '*.googleapis.cn', '*.googlecommerce.com', '*.googlevideo.com', '*.gstatic.com', '*.urchin.com', '*.url.google.com', '*.youtube-nocookie.com', '*.youtube.com', '*.youtubeeducation.com', '*.ytimg.com', 'android.com', 'g.co', 'goo.gl', 'google-analytics.com', 'google.com', 'googlecommerce.com', 'urchin.com', 'youtu.be', 'youtube.com', 'youtubeeducation.com'
    

    The URL that was requested was https://android.clients.google.com/auth. The strange thing is that the certificate is indeed invalid, as pointed out by the error message. However, when I visit the URL in google chrome browser, I got a different certificate, which is valid. However, however, when I visit the URL in Internet explorer, I got the same invalid certificate as googleplay-api. The thumbprint of the invalid certificate is ad 3c 56 fb e8 c0 62 b0 ff 89 21 52 98 b1 a1 d4 94 a4 1c 84, while the valid one is ‎77 b7 b3 81 72 29 6c 8e 3b 40 24 f8 d7 85 4c e0 7f ae 4f 43.

    I couldn't figure out the reason for this strange behaviour. It's probably related my web proxy.

    I finally had to workaround this problem by changing urllib3:

    --- /usr/lib/python2.7/site-packages/urllib3/connectionpool.py.orig     2014-01-22 14:59:28.939379250 +0800
    +++ /usr/lib/python2.7/site-packages/urllib3/connectionpool.py  2014-01-22 14:59:37.328378991 +0800
    @@ -574,7 +574,7 @@
             self.cert_reqs = cert_reqs
             self.ca_certs = ca_certs
             self.ssl_version = ssl_version
    -        self.assert_hostname = assert_hostname
    +        self.assert_hostname = False
             self.assert_fingerprint = assert_fingerprint
    
         def _prepare_conn(self, connection):
    
  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    ubuntu - Error with python-setuptools doing "sudo easy_install python-graph-core"
  • Dan

    Using easy_install, part of the python-setuptools, I get the following error:

    $ sudo easy_install python-graph-core
    [sudo] password for dan: 
    Searching for python-graph-core
    Reading http://pypi.python.org/simple/python-graph-core/
    Reading http://code.google.com/p/python-graph/
    Reading http://code.google.com/p/python-graph/downloads/list?can=1
    Reading http://code.google.com/p/python-graph/downloads/list
    Best match: python-graph-core 1.7.0
    Downloading http://python-graph.googlecode.com/files/python-graph-core-1.7.0.tar.gz
    Processing python-graph-core-1.7.0.tar.gz
    Running python-graph-core-1.7.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-GwpYiM/python-graph-core-1.7.0/egg-dist-tmp-1yqbyV
    setup.py:8: Warning: 'as' will become a reserved keyword in Python 2.6
    Traceback (most recent call last):
      File "/usr/bin/easy_install", line 8, in <module>
        load_entry_point('setuptools==0.6c9', 'console_scripts', 'easy_install')()
      File "/usr/lib/python2.5/site-packages/setuptools/command/easy_install.py", line 1671, in main
        with_ei_usage(lambda:
      File "/usr/lib/python2.5/site-packages/setuptools/command/easy_install.py", line 1659, in with_ei_usage
        return f()
      File "/usr/lib/python2.5/site-packages/setuptools/command/easy_install.py", line 1675, in <lambda>
        distclass=DistributionWithoutHelpCommands, **kw
      File "/usr/lib/python2.5/distutils/core.py", line 151, in setup
        dist.run_commands()
      File "/usr/lib/python2.5/distutils/dist.py", line 974, in run_commands
        self.run_command(cmd)
      File "/usr/lib/python2.5/distutils/dist.py", line 994, in run_command
        cmd_obj.run()
      File "/usr/lib/python2.5/site-packages/setuptools/command/easy_install.py", line 211, in run
        self.easy_install(spec, not self.no_deps)
      File "/usr/lib/python2.5/site-packages/setuptools/command/easy_install.py", line 446, in easy_install
        return self.install_item(spec, dist.location, tmpdir, deps)
      File "/usr/lib/python2.5/site-packages/setuptools/command/easy_install.py", line 476, in install_item
        dists = self.install_eggs(spec, download, tmpdir)
      File "/usr/lib/python2.5/site-packages/setuptools/command/easy_install.py", line 655, in install_eggs
        return self.build_and_install(setup_script, setup_base)
      File "/usr/lib/python2.5/site-packages/setuptools/command/easy_install.py", line 930, in build_and_install
        self.run_setup(setup_script, setup_base, args)
      File "/usr/lib/python2.5/site-packages/setuptools/command/easy_install.py", line 919, in run_setup
        run_setup(setup_script, args)
      File "/usr/lib/python2.5/site-packages/setuptools/sandbox.py", line 27, in run_setup
        lambda: execfile(
      File "/usr/lib/python2.5/site-packages/setuptools/sandbox.py", line 63, in run
        return func()
      File "/usr/lib/python2.5/site-packages/setuptools/sandbox.py", line 29, in <lambda>
        {'__file__':setup_script, '__name__':'__main__'}
      File "setup.py", line 8
        except ImportError as ie:
                            ^
    SyntaxError: invalid syntax
    

    Any suggestions to what I may be doing wrong?

    Thanks, Dan


  • Related Answers
  • Dan

    Its not an issue with easy-install. This error is from having python 2.5 instead of python 2.6 which is required by python-graph.