The problem
When requesting from opentdb, I get the following error:
Traceback (most recent call last):
File "trivia.py", line 3, in <module>
print(requests.get('https://opentdb.com/api.php?amount=1'))
File "/Users/edl/Library/Python/3.4/lib/python/site-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/Users/edl/Library/Python/3.4/lib/python/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/edl/Library/Python/3.4/lib/python/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/Users/edl/Library/Python/3.4/lib/python/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/Users/edl/Library/Python/3.4/lib/python/site-packages/requests/adapters.py", line 506, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='opentdb.com', port=443): Max retries exceeded with url: /api.php?amount=1 (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:600)'),))
I have looked at this question as well as the issues page on github but none of the solutions are working. Requesting from other sites works completely fine on my computer, so I am not sure what is wrong.
Further weirdness
However, running this code in js gives no errors, so I am not sure what is wrong with requests
.
function get(url) {
return new Promise((resolve, reject) => {
const req = new XMLHttpRequest();
req.open("GET", url);
req.onload = () => req.status === 200 ? resolve(req.response) : reject(req.statusText);
req.onerror = () => reject("Network Error");
req.send();
});
}
get('https://opentdb.com/api.php?amount=1').then(console.log)
Even FURTHER weirdness
When running the same code in repl.it, everything works with no problems. Is it because of my computer that this isn't working? I'm not sure why it works from repl.it but not my own computer.
Minimal, Complete, and Verifiable example:
import requests
print(requests.get('https://opentdb.com/api.php?amount=1'))
More information:
Using python 3.4.4
Info about requests
:
Name: requests
Version: 2.18.4
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: Apache 2.0
Location: /Users/edl/Library/Python/3.4/lib/python/site-packages
Requires: urllib3, certifi, idna, chardet