遇到一个网页提交的数据是 json 格式,但是里面传入的参数一个是 json query 的查询语句,一个是用户名,使用 Fiddle 可以重发看获取到返回结果,用 python 提交就不行,应该是 json 在传输的过程中没有被正确识别,求大佬指教。
网页端原传入参数为
{"query":"\n query Profile($usernameOrAddress: String!) {\n profile(usernameOrAddress: $usernameOrAddress) {\n id\n username\n pfp {\n ...FullBareAsset\n }\n decagon {\n ...FullBareAsset\n }\n banner {\n ...FullBareAsset\n }\n bio\n twitterUsername\n discordUsername\n showListings\n addresses\n followedByCount\n followingCount\n }\n}\n \n fragment FullBareAsset on BareAsset {\n id\n provider\n contract\n tokenId\n mediaUrl\n previewStorageKey\n previewMimeType\n previewAspectRatio\n storageKey\n mimeType\n tokenUrl\n name\n multimediaUrl\n aspectRatio\n metadata\n}\n ","variables":{"usernameOrAddress":"Datdz172"}}
k = {"query":"\n query Profile($usernameOrAddress: String!) {\n profile(usernameOrAddress: $usernameOrAddress) {\n id\n username\n pfp {\n ...FullBareAsset\n }\n decagon {\n ...FullBareAsset\n }\n banner {\n ...FullBareAsset\n }\n bio\n twitterUsername\n discordUsername\n showListings\n addresses\n followedByCount\n followingCount\n }\n}\n \n fragment FullBareAsset on BareAsset {\n id\n provider\n contract\n tokenId\n mediaUrl\n previewStorageKey\n previewMimeType\n previewAspectRatio\n storageKey\n mimeType\n tokenUrl\n name\n multimediaUrl\n aspectRatio\n metadata\n}\n ","variables":{"usernameOrAddress":"Datdz172"}}
response = requests.post(APIurl, proxies=proxies, json=k, headers=header, verify=False)
1
fkdtz 2022-08-15 10:41:06 +08:00
猜测第一种请求方式是对的,不过返回的是加密后的内容比如 AES ,你需要找到密钥解密。
|
3
Trim21 2022-08-15 10:45:36 +08:00 via Android
这是 graphql 吧?
|
4
Trim21 2022-08-15 10:48:27 +08:00 via Android
我猜你第一种方法是对的,但是 requests 判断相应编码出错了。你看看 Fiddle 的响应头和 requests 的响应编码能不能对得上。
|
6
luboyan OP 破案了,不管是方法一还是二,都可以解决,和 graphql 关系也不大,是因为请求头使用了网页端的
Accept-Encoding: gzip, deflate, br 默认采用了 br 压缩,只要修改成 Accept-Encoding:deflate 就可以正确读取到数据,谢谢大佬们的指点。 |