#python #python-requests #urllib3
Вопрос:
У меня есть следующий тестовый код
import requests
import json
r = requests.get('https://api.github.com/user')
print(r.status_code)
Это приводит к следующей ошибке, я переустановил запросы и модули urllib3, но это не помогло
File "/data//temp/scratchprojects/data structures/test.py", line 4, in <module>
r = requests.get('https://api.github.com/user')
File "/data/my_venv/lib/python3.8/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/data/my_venv/lib/python3.8/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/data/my_venv/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/data/my_venv/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/data/my_venv/lib/python3.8/site-packages/requests/adapters.py", line 412, in send
conn = self.get_connection(request.url, proxies)
File "/data/my_venv/lib/python3.8/site-packages/requests/adapters.py", line 315, in get_connection
conn = self.poolmanager.connection_from_url(url)
File "/data/my_venv/lib/python3.8/site-packages/urllib3/poolmanager.py", line 298, in connection_from_url
return self.connection_from_host(
File "/data/my_venv/lib/python3.8/site-packages/urllib3/poolmanager.py", line 245, in connection_from_host
return self.connection_from_context(request_context)
File "/data/my_venv/lib/python3.8/site-packages/urllib3/poolmanager.py", line 260, in connection_from_context
return self.connection_from_pool_key(pool_key, request_context=request_context)
File "/data/my_venv/lib/python3.8/site-packages/urllib3/poolmanager.py", line 281, in connection_from_pool_key
pool = self._new_pool(scheme, host, port, request_context=request_context)
File "/data/my_venv/lib/python3.8/site-packages/urllib3/poolmanager.py", line 213, in _new_pool
return pool_cls(host, port, **request_context)
File "/data/my_venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 906, in __init__
HTTPConnectionPool.__init__(
File "/data/my_venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 197, in __init__
self.pool = self.QueueCls(maxsize)
TypeError: __init__() takes 1 positional argument but 2 were given
Комментарии:
1. Работает на меня
Python 3.9.7
—print(requests.get('https://api.github.com/user').status_code)
в РЕПЛ
Ответ №1:
похоже на поврежденную библиотеку. После удаления виртуальной среды и ее повторного создания проблема была устранена