0

I can't request any page. Am I doing something wrong? I've used this code before, so I don't know what's happening. I've tried other ways as well. Seems to just not get a response. Did something change with requests? Or could it be an anti-virus firewall thing?

Any help?

>>> import requests, json
>>> url = 'https://api.chess.com/pub/player/Hikaru/games/archives'
>>> resp= requests.get(url)
 
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    resp= requests.get(url)
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1016, in _send_output
    self.send(msg)
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 977, in send
    self.sock.sendall(data)
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\contrib\pyopenssl.py", line 328, in sendall
    sent = self._send_until_done(data[total_sent:total_sent + SSL_WRITE_BLOCKSIZE])
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\contrib\pyopenssl.py", line 317, in _send_until_done
    return self.connection.send(data)
  File "C:\Users\\AppData\Local\Programs\Python\Python37\lib\site-packages\OpenSSL\SSL.py", line 1644, in send
    with _from_buffer(buf) as data:
AttributeError: __enter__
import requests, json
url = 'https://api.chess.com/pub/player/Hikaru/games/archives'
resp= requests.get(url)
print(resp)
Deadman0
  • 11
  • 4
  • Is this the entire code, or is it an extract of a class? – Dbercules Feb 22 '21 at 16:38
  • I just used this code in idle for another test. I've tried other code i made that works when made an executable but not when i run it as code – Deadman0 Feb 22 '21 at 16:41
  • https://github.com/George-Kaloudis/Chess.com-Game-Downloader this is the one which the executable works but not the code – Deadman0 Feb 22 '21 at 16:42
  • Ok so I can see already that your question is missing critical information that would allow someone to provide an answer. You need to provide clear, reproducible code for us to run on our own machines, and while the three lines provide that, they don't replicate the surrounding environment that causes the issue. You should tidy up the question for future readers, despite this being a well-reported error. – Dbercules Feb 22 '21 at 16:44
  • The error at the bottom of that Traceback is what's important - `AttributeError: __enter__`. Google that, and you'd have landed somewhere like [this answer](https://stackoverflow.com/a/53564918/5568675). There's the solution. – Dbercules Feb 22 '21 at 16:46
  • Well it's not. Because while i can run these linis of code online in programiz.com, i can't on my pc – Deadman0 Feb 22 '21 at 16:50
  • The environment on programiz.com and the environment on your computer are different. I suspect from looking at your repo's code that you've overwritten the `open` method somewhere within your environment which is a known and frequent cause of that error. – Dbercules Feb 22 '21 at 16:52
  • That aside, the question really needs to replicate the error, as the code you've supplied will work totally fine for any developer on a clean environment, and not produce the error. – Dbercules Feb 22 '21 at 16:54
  • I run only these 3 lines on a new file and get the error. No repo. No nothing . just these lines i have – Deadman0 Feb 22 '21 at 16:54
  • I suspect that you've written your code in the default non-virtual environment. This means that when making changes to core Python functions (such as `open`), the change won't be restricted to the development environment, and will instead be felt across the full reach of Python's installation on your computer. That's why you're facing the issue in a 'fresh' file - it's still within the same environment. Try that same code in a truly fresh and clean [Python virtual environment](https://docs.python.org/3/library/venv.html). – Dbercules Feb 22 '21 at 17:00

0 Answers0