Python 爬虫报错AttributeError: __enter__

代码:

import requests

r = requests.get('https://github.com/favicon.ico')
print(r.text)
print(r.content)

报错:

Traceback (most recent call last):
  File "D:/Python/untitled/venv/Include/爬虫/Test0015.py", line 3, in <module>
    r = requests.get('https://github.com/favicon.ico')
  File "D:\Python3-5.2.0\Anaconda\lib\site-packages\requests\api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "D:\Python3-5.2.0\Anaconda\lib\site-packages\requests\api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "D:\Python3-5.2.0\Anaconda\lib\site-packages\requests\sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "D:\Python3-5.2.0\Anaconda\lib\site-packages\requests\sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "D:\Python3-5.2.0\Anaconda\lib\site-packages\requests\adapters.py", line 440, in send
    timeout=timeout
  File "D:\Python3-5.2.0\Anaconda\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "D:\Python3-5.2.0\Anaconda\lib\site-packages\urllib3\connectionpool.py", line 357, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "D:\Python3-5.2.0\Anaconda\lib\http\client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "D:\Python3-5.2.0\Anaconda\lib\http\client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "D:\Python3-5.2.0\Anaconda\lib\http\client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "D:\Python3-5.2.0\Anaconda\lib\http\client.py", line 1026, in _send_output
    self.send(msg)
  File "D:\Python3-5.2.0\Anaconda\lib\http\client.py", line 986, in send
    self.sock.sendall(data)
  File "D:\Python3-5.2.0\Anaconda\lib\site-packages\urllib3\contrib\pyopenssl.py", line 316, in sendall
    sent = self._send_until_done(data[total_sent:total_sent + SSL_WRITE_BLOCKSIZE])
  File "D:\Python3-5.2.0\Anaconda\lib\site-packages\urllib3\contrib\pyopenssl.py", line 304, in _send_until_done
    return self.connection.send(data)
  File "D:\Python3-5.2.0\Anaconda\lib\site-packages\OpenSSL\SSL.py", line 1644, in send
    with _from_buffer(buf) as data:
AttributeError: __enter__

Process finished with exit code 1

我也是才开始学习python爬虫,很难理解这些错误产生的原因,也在网上搜过,还是没有解决,希望有大佬能帮我看一下,感谢!

你可能感兴趣的:(Python爬虫,python)