Столкнулся вот с таким кодом ошибки
Код ошибки: TypeError: the JSON object must be str, bytes or bytearray, not Response
Я банально не понимаю в чем проблема,если синтаксис программы правильный
import json
import urllib.request
import requests
headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'}
URL = 'https://www.instagram.com/zuck/?__a=1'
r = requests.get(URL,headers=headers)
data = json.loads(r)
print("id",data['graphql']['user']['id'])
>>> get_user_id('dwalinforkbeard')
Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\packages\urllib3\connection.py", line 141, in _new_conn
conn = connection.create_connection(
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\packages\urllib3\util\connection.py", line 75, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\socket.py", line 953, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 592, in urlopen
httplib_response = self._make_request(conn, method, url,
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 352, in _make_request
self._validate_conn(conn)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 831, in _validate_conn
conn.connect()
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\packages\urllib3\connection.py", line 254, in connect
conn = self._new_conn()
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\packages\urllib3\connection.py", line 150, in _new_conn
raise NewConnectionError(
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x0000020CD774F160>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 413, in send
resp = conn.urlopen(
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 639, in urlopen
retries = retries.increment(method, url, error=e, _pool=self,
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\packages\urllib3\util\retry.py", line 287, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.instagram.comdwalinforkbeard', port=443): Max retries exceeded with url: /?__a=1 (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x0000020CD774F160>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
get_user_id('dwalinforkbeard')
File "C:\Users\USER\Desktop\main.py.py", line 8, in get_user_id
r = requests.get(f'{URL}{username}/?__a=1', headers=HEADERS)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 70, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 487, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.instagram.comdwalinforkbeard', port=443): Max retries exceeded with url: /?__a=1 (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x0000020CD774F160>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
json
?