o19s / relevant-search-book

Code and Examples for Relevant Search
297 stars 107 forks source link

TMDB ssl errors #13

Open softwaredoug opened 8 years ago

softwaredoug commented 8 years ago

Running the code in Appendix A gives errors about trusting SSL on my Ubuntu 14.04 machine.

If I run the following "hello world" script:

import requests
import os

# you'll need to have an API key for TMDB
# to run these examples,
# run export TMDB_API_KEY=<YourAPIKey>
tmdb_api_key = os.environ["TMDB_API_KEY"]
tmdb_api = requests.Session()
tmdb_api.params={'api_key': tmdb_api_key}

httpResp = tmdb_api.get('https://api.themoviedb.org/3/movie/top_rated')

I recieve the error

(venv)doug@76$~/ws/relevant-search-book/ipython(ma) $ python tmdb_hello_world.py 
/home/doug/workspace/relevant-search-book/ipython/venv/local/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
Traceback (most recent call last):
  File "tmdb_hello_world.py", line 11, in <module>
    httpResp = tmdb_api.get('https://api.themoviedb.org/3/movie/top_rated')
  File "/home/doug/workspace/relevant-search-book/ipython/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 476, in get
    return self.request('GET', url, **kwargs)
  File "/home/doug/workspace/relevant-search-book/ipython/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 464, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/doug/workspace/relevant-search-book/ipython/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/home/doug/workspace/relevant-search-book/ipython/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [Errno 1] _ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
softwaredoug commented 8 years ago

Workaround (for any book readers that encounter this in the time being) is to set verify=False in the requests calls, ie

httpResp = tmdb_api.get('https://api.themoviedb.org/3/movie/top_rated', verify=False)

This disables authentication that TMDB is who they say they are.

softwaredoug commented 8 years ago

I can't recreate this in an Ubuntu 14.04 VM. Must be my laptop... :-/