python - 为什么我的 python POST 请求无法收集我想要的信息?
问题描述
我正在尝试使用此配置文件中的 python 请求收集关注者列表,当我尝试使用所需的标头向 API 发送 POST 请求时,我收到错误...我做错了什么?
这是我的代码:
from requests.api import head
address = '0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3'
followerurl = 'https://api-mainnet.rarible.com/marketplace/api/v4/followers?owner={}'.format(address)
headers = {
"authority": "api-mainnet.rarible.com",
"method": "POST",
"path": "/marketplace/api/v4/followings?owner=0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3",
"scheme": "https",
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "el,en-US;q=0.9,en;q=0.8",
"content-length": "11",
"content-type": "application/json",
"origin": "https://rarible.com",
"referer": "https://rarible.com/",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"user-agent": "Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Mobile Safari/537.36",
"x-fingerprint": "822426b6593854039ff5063f26456a61",
}
data = requests.post(followerurl, headers=headers)
print(data.content)
程序等待 10 秒,然后我收到此错误:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 1344, in getresponse
response.begin()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 307, in begin
version, status, reason = self._read_status()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 268, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\util\retry.py", line 532, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\packages\six.py", line 769, in reraise
raise value.with_traceback(tb)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\urllib3\connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 1344, in getresponse
response.begin()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 307, in begin
version, status, reason = self._read_status()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 268, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 25, in <module>
data = requests.post(followerurl, headers=headers)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\api.py", line 117, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\requests\adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
更新了最近的错误,上一个不完整
解决方案
您没有在帖子中包含用户字符串。尝试这个:
import requests
address = '0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3'
followerurl = 'https://api-mainnet.rarible.com/marketplace/api/v4/followers'
headers = {
"user-agent": "Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Mobile Safari/537.36",
}
payload = {
'size': '20'}
query = {'user':'%s' %address}
data = requests.post(followerurl, params=query, json=payload, headers=headers).json()
输出:
以下是返回数据中前 2 个元素的示例:
print(data[:2])
[{'following': {'id': '6183b55fdf746c28434736d0', 'owner': '0x1b962b82dd9af59701bdba86608cf7ea4b3efedd', 'user': '0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3', 'createDate': '2021-11-04T10:26:39.633+00:00', 'deleted': False}, 'owner': {'id': '0x1b962b82dd9af59701bdba86608cf7ea4b3efedd', 'type': 'USER', 'name': 'MASYANA58^^.', 'image': 'ipfs://ipfs/QmZ7V5d95bDKhHPg6UAWZ5HhjHxUzwtJeyiJBCwVV2UPQR', 'shortUrl': 'masyana58', 'website': 'https://www.instagram.com/invites/contact/?i=15i2h5oepcxgc&utm_content=5zmtkl6', 'description': 'Hello, i am masyana58.I am here to show you my imagination and my vision.I hope, you will enjoy my creations', 'badges': ['VERIFIED'], 'cover': 'ipfs://ipfs/QmdB1UP6zVLfXNeCEw3zr9fxb5uP1ArhJgPh4ossgq7jwo', 'coverMedia': [{'url': 'https://img.rarible.com/prod/image/upload/prod-users/0x1b962b82dd9af59701bdba86608cf7ea4b3efedd/cover/QmdB1UP6zVLfXNeCEw3zr9fxb5uP1ArhJgPh4ossgq7jwo', 'sizeType': 'ORIGINAL', 'contentType': 'IMAGE'}, {'url': 'https://img.rarible.com/prod/image/upload/t_cover_preview/prod-users/0x1b962b82dd9af59701bdba86608cf7ea4b3efedd/cover/QmdB1UP6zVLfXNeCEw3zr9fxb5uP1ArhJgPh4ossgq7jwo', 'sizeType': 'PREVIEW', 'contentType': 'IMAGE', 'dimension': {'width': 1000, 'height': 200}, 'cropMode': 'CROP'}, {'url': 'https://img.rarible.com/prod/image/upload/t_cover_big/prod-users/0x1b962b82dd9af59701bdba86608cf7ea4b3efedd/cover/QmdB1UP6zVLfXNeCEw3zr9fxb5uP1ArhJgPh4ossgq7jwo', 'sizeType': 'BIG', 'contentType': 'IMAGE', 'dimension': {'width': 2200, 'height': 400}, 'cropMode': 'CROP'}, {'url': 'https://img.rarible.com/prod/image/upload/t_cover_placeholder/prod-users/0x1b962b82dd9af59701bdba86608cf7ea4b3efedd/cover/QmdB1UP6zVLfXNeCEw3zr9fxb5uP1ArhJgPh4ossgq7jwo', 'sizeType': 'PLACEHOLDER', 'contentType': 'IMAGE', 'dimension': {'width': 55, 'height': 10}, 'cropMode': 'CROP'}], 'imageMedia': [{'url': 'https://img.rarible.com/prod/image/upload/prod-users/0x1b962b82dd9af59701bdba86608cf7ea4b3efedd/avatar/QmZ7V5d95bDKhHPg6UAWZ5HhjHxUzwtJeyiJBCwVV2UPQR', 'sizeType': 'ORIGINAL', 'contentType': 'IMAGE'}, {'url': 'https://img.rarible.com/prod/image/upload/t_avatar_preview/prod-users/0x1b962b82dd9af59701bdba86608cf7ea4b3efedd/avatar/QmZ7V5d95bDKhHPg6UAWZ5HhjHxUzwtJeyiJBCwVV2UPQR', 'sizeType': 'PREVIEW', 'contentType': 'IMAGE', 'dimension': {'width': 30, 'height': 30}, 'cropMode': 'THUMB'}, {'url': 'https://img.rarible.com/prod/image/upload/t_avatar_big/prod-users/0x1b962b82dd9af59701bdba86608cf7ea4b3efedd/avatar/QmZ7V5d95bDKhHPg6UAWZ5HhjHxUzwtJeyiJBCwVV2UPQR', 'sizeType': 'BIG', 'contentType': 'IMAGE', 'dimension': {'width': 240, 'height': 240}, 'cropMode': 'THUMB'}], 'followings': 334, 'followers': 124, 'blacklisted': False, 'blockchain': 'ETHEREUM'}, 'user': {'id': '0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3', 'type': 'USER', 'name': 'ZafGod.eth', 'image': 'ipfs://ipfs/QmaM3Lvd8kiwCekq6cuhWh5SA7RpbN2upQM1R6QoefWHuS', 'shortUrl': 'artshop', 'website': 'http://Instagram.com/zafgod', 'emoji': '', 'description': 'Artist-- \nJoin the club on discord https://discord.com/invite/NHc7HQv', 'badges': ['VERIFIED'], 'cover': 'ipfs://ipfs/Qmc6qi78MyEWwvyCa3gnSA8rKCu4jVb19nZorn3NccfgcJ', 'coverMedia': [{'url': 'https://img.rarible.com/prod/image/upload/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/cover/Qmc6qi78MyEWwvyCa3gnSA8rKCu4jVb19nZorn3NccfgcJ', 'sizeType': 'ORIGINAL', 'contentType': 'IMAGE'}, {'url': 'https://img.rarible.com/prod/image/upload/t_cover_preview/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/cover/Qmc6qi78MyEWwvyCa3gnSA8rKCu4jVb19nZorn3NccfgcJ', 'sizeType': 'PREVIEW', 'contentType': 'IMAGE', 'dimension': {'width': 1000, 'height': 200}, 'cropMode': 'CROP'}, {'url': 'https://img.rarible.com/prod/image/upload/t_cover_big/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/cover/Qmc6qi78MyEWwvyCa3gnSA8rKCu4jVb19nZorn3NccfgcJ', 'sizeType': 'BIG', 'contentType': 'IMAGE', 'dimension': {'width': 2200, 'height': 400}, 'cropMode': 'CROP'}, {'url': 'https://img.rarible.com/prod/image/upload/t_cover_placeholder/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/cover/Qmc6qi78MyEWwvyCa3gnSA8rKCu4jVb19nZorn3NccfgcJ', 'sizeType': 'PLACEHOLDER', 'contentType': 'IMAGE', 'dimension': {'width': 55, 'height': 10}, 'cropMode': 'CROP'}], 'imageMedia': [{'url': 'https://img.rarible.com/prod/image/upload/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/avatar/QmaM3Lvd8kiwCekq6cuhWh5SA7RpbN2upQM1R6QoefWHuS', 'sizeType': 'ORIGINAL', 'contentType': 'IMAGE'}, {'url': 'https://img.rarible.com/prod/image/upload/t_avatar_preview/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/avatar/QmaM3Lvd8kiwCekq6cuhWh5SA7RpbN2upQM1R6QoefWHuS', 'sizeType': 'PREVIEW', 'contentType': 'IMAGE', 'dimension': {'width': 30, 'height': 30}, 'cropMode': 'THUMB'}, {'url': 'https://img.rarible.com/prod/image/upload/t_avatar_big/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/avatar/QmaM3Lvd8kiwCekq6cuhWh5SA7RpbN2upQM1R6QoefWHuS', 'sizeType': 'BIG', 'contentType': 'IMAGE', 'dimension': {'width': 240, 'height': 240}, 'cropMode': 'THUMB'}], 'followings': 3752, 'followers': 2782, 'blacklisted': False, 'blockchain': 'ETHEREUM'}, 'id': '6183b55fdf746c28434736d0'}, {'following': {'id': '6183a81cb8c1e71a27395adc', 'owner': '0x7d2185a5bb721d8cb9d8b8382d9739c33bb8beb3', 'user': '0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3', 'createDate': '2021-11-04T09:30:04.044+00:00', 'deleted': False}, 'owner': {'id': '0x7d2185a5bb721d8cb9d8b8382d9739c33bb8beb3', 'type': 'USER', 'name': 'TGiacinto', 'image': 'ipfs://ipfs/QmQCroMLcZaRgAtjAhfLbMARwz1yMVP5ppt9KBFcF8TWso', 'shortUrl': 'tgiacinto', 'badges': [], 'coverMedia': [], 'imageMedia': [{'url': 'https://img.rarible.com/prod/image/upload/prod-users/0x7d2185a5bb721d8cb9d8b8382d9739c33bb8beb3/avatar/QmQCroMLcZaRgAtjAhfLbMARwz1yMVP5ppt9KBFcF8TWso', 'sizeType': 'ORIGINAL', 'contentType': 'IMAGE'}, {'url': 'https://img.rarible.com/prod/image/upload/t_avatar_preview/prod-users/0x7d2185a5bb721d8cb9d8b8382d9739c33bb8beb3/avatar/QmQCroMLcZaRgAtjAhfLbMARwz1yMVP5ppt9KBFcF8TWso', 'sizeType': 'PREVIEW', 'contentType': 'IMAGE', 'dimension': {'width': 30, 'height': 30}, 'cropMode': 'THUMB'}, {'url': 'https://img.rarible.com/prod/image/upload/t_avatar_big/prod-users/0x7d2185a5bb721d8cb9d8b8382d9739c33bb8beb3/avatar/QmQCroMLcZaRgAtjAhfLbMARwz1yMVP5ppt9KBFcF8TWso', 'sizeType': 'BIG', 'contentType': 'IMAGE', 'dimension': {'width': 240, 'height': 240}, 'cropMode': 'THUMB'}], 'followings': 13, 'followers': 9, 'blacklisted': False, 'blockchain': 'ETHEREUM'}, 'user': {'id': '0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3', 'type': 'USER', 'name': 'ZafGod.eth', 'image': 'ipfs://ipfs/QmaM3Lvd8kiwCekq6cuhWh5SA7RpbN2upQM1R6QoefWHuS', 'shortUrl': 'artshop', 'website': 'http://Instagram.com/zafgod', 'emoji': '', 'description': 'Artist-- \nJoin the club on discord https://discord.com/invite/NHc7HQv', 'badges': ['VERIFIED'], 'cover': 'ipfs://ipfs/Qmc6qi78MyEWwvyCa3gnSA8rKCu4jVb19nZorn3NccfgcJ', 'coverMedia': [{'url': 'https://img.rarible.com/prod/image/upload/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/cover/Qmc6qi78MyEWwvyCa3gnSA8rKCu4jVb19nZorn3NccfgcJ', 'sizeType': 'ORIGINAL', 'contentType': 'IMAGE'}, {'url': 'https://img.rarible.com/prod/image/upload/t_cover_preview/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/cover/Qmc6qi78MyEWwvyCa3gnSA8rKCu4jVb19nZorn3NccfgcJ', 'sizeType': 'PREVIEW', 'contentType': 'IMAGE', 'dimension': {'width': 1000, 'height': 200}, 'cropMode': 'CROP'}, {'url': 'https://img.rarible.com/prod/image/upload/t_cover_big/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/cover/Qmc6qi78MyEWwvyCa3gnSA8rKCu4jVb19nZorn3NccfgcJ', 'sizeType': 'BIG', 'contentType': 'IMAGE', 'dimension': {'width': 2200, 'height': 400}, 'cropMode': 'CROP'}, {'url': 'https://img.rarible.com/prod/image/upload/t_cover_placeholder/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/cover/Qmc6qi78MyEWwvyCa3gnSA8rKCu4jVb19nZorn3NccfgcJ', 'sizeType': 'PLACEHOLDER', 'contentType': 'IMAGE', 'dimension': {'width': 55, 'height': 10}, 'cropMode': 'CROP'}], 'imageMedia': [{'url': 'https://img.rarible.com/prod/image/upload/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/avatar/QmaM3Lvd8kiwCekq6cuhWh5SA7RpbN2upQM1R6QoefWHuS', 'sizeType': 'ORIGINAL', 'contentType': 'IMAGE'}, {'url': 'https://img.rarible.com/prod/image/upload/t_avatar_preview/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/avatar/QmaM3Lvd8kiwCekq6cuhWh5SA7RpbN2upQM1R6QoefWHuS', 'sizeType': 'PREVIEW', 'contentType': 'IMAGE', 'dimension': {'width': 30, 'height': 30}, 'cropMode': 'THUMB'}, {'url': 'https://img.rarible.com/prod/image/upload/t_avatar_big/prod-users/0xe744d23107c9c98df5311ff8c1c8637ec3ecf9f3/avatar/QmaM3Lvd8kiwCekq6cuhWh5SA7RpbN2upQM1R6QoefWHuS', 'sizeType': 'BIG', 'contentType': 'IMAGE', 'dimension': {'width': 240, 'height': 240}, 'cropMode': 'THUMB'}], 'followings': 3752, 'followers': 2782, 'blacklisted': False, 'blockchain': 'ETHEREUM'}, 'id': '6183a81cb8c1e71a27395adc'}]
推荐阅读
- oracle - Oracle Application Express 的问题
- google-cloud-platform - ESP32 到 GCP IOT Core 连接失败
- css - 输入滑块(v-slider)死区上的标签
- c# - 当父母移动平台时,角色移动缓慢
- javascript - 为什么当我将轨道推到数组时,数组中的所有元素都改变了
- javascript - 如何固定特定大小的输入文本的长度?在 HTML 5 中
- java - ANTLR4 中基于目标的成员
- html - 并排调整列表项而不滚动
- swift - 带有 countDownTimer 的 UIDatePicker 显示“0 小时 2 分钟”
- java - 如何在 ALfresco 中创建父/子关系模型