我试图使用cURL获取一个HTTP请求响应,这很好。然而,当我在Python中使用“请求”包时,我没有得到任何响应(它只是超时,没有错误或返回响应)。
我的cURL代码如下:
curl 'http://144.126.138.12:17001/api/v0/get-posts-stateless' \
-H 'authority: bitclout.com' \
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"' \
-H 'accept: application/json, text/plain, */*' \
-H 'sec-ch-ua-mobile: ?1' \
-H 'user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Mobile Safari/537.36' \
-H 'content-type: application/json' \
-H 'origin: https://bitclout.com' \
-H 'sec-fetch-site: same-origin' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-dest: empty' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'cookie: datadome=2P0n.mJzUY2hB5B03Tc2hild-xu2AkuX~-mIgJ2VRW-j35yl3njRPJEKTAHgcxyQdxrX-E3vQnr5GSEA~DfK3nyrtPJB1M77Ndccn3BZnf; INGRESSCOOKIE=389b5e3fc60c40d6115364749da12fd0; amp_23345b=c6QQHrpE_pvlOyAXAEKiaE.QkMxWUxpRWIzMVVHWHZ4bUZ0N0piQktIS2pjRjJTMUhZNVNkOEMzWlp5ZTFmQnVEVTVOZnNoYw==..1f6htdgom.1f6htgqqm.4r.0.4r' \
--data-raw '{"PostHashHex":"","ReaderPublicKeyBase58Check":"BC1YLiUgto51FaPyCPwf2LGGQcCo4qa3XM3KY1zAbK8jCzaDCc4bU27","OrderBy":"newest","StartTstampSecs":null,"PostContent":"","NumToFetch":400,"FetchSubcomments":false,"GetPostsForFollowFeed":false,"GetPostsForGlobalWhitelist":false,"GetPostsByClout":false,"PostsByCloutMinutesLookback":0,"AddGlobalFeedBool":false}' \
--compressed
当我在cURL代码中使用-v时,我得到以下消息:
POST/api/v0/get posts无状态HTTP/1.1主机:144.126.138.12:17001接受编码:deflate,gzip权限:bitclout。com sec chua:“不是品牌”;v=“99”,“铬”;v=“90”,“谷歌浏览器”;v=“90”接受:application/json,text/plain,/sec-ch-ua-mobile:?1个用户代理:Mozilla/5.0(Linux;Android 6.0;Nexus 5 Build/MRA58N)AppleWebKit/537.36(KHTML,比如Gecko)Chrome/90.0.4430.212 Mobile Safari/537.36内容类型:应用程序/json来源:https://bitclout.comsec fetch site:同源sec fetch mode:cors sec fetch dest:空接受语言:en US,en;q=0.9 cookie:datadome=2P0n。mJzUY2hB5B03Tc2hild-xu2AkuX~-mIgJ2VRW-j35yl3njRPJEKTAHgcxyQdxrX-E3vQnr5GSEA~DfK3nyrtPJB1M77Ndccn3BZnf;Ingrescookie=389b5e3fc60c40d611364749da12fd0;amp_23345b=c6qhrpe_pvlOyAXAEKiaE。qkmxwuxprwizmvvhwhz4buz0n0piqktis2pjrjtmuhznvnkoemzwlp5ztfmqnvetvoznnoyw==。。1f6htdgom。1f6htgqqm。4r。0.4r内容长度:351
我的Python代码使用请求如下:
import requests
headers = {
'authority': 'bitclout.com',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
'accept': 'application/json, text/plain, */*',
'sec-ch-ua-mobile': '?1',
'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Mobile Safari/537.36',
'content-type': 'application/json',
'origin': 'https://bitclout.com',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'accept-language': 'en-US,en;q=0.9',
'cookie': 'datadome=2P0n.mJzUY2hB5B03Tc2hild-xu2AkuX~-mIgJ2VRW-j35yl3njRPJEKTAHgcxyQdxrX-E3vQnr5GSEA~DfK3nyrtPJB1M77Ndccn3BZnf; INGRESSCOOKIE=389b5e3fc60c40d6115364749da12fd0; amp_23345b=c6QQHrpE_pvlOyAXAEKiaE.QkMxWUxpRWIzMVVHWHZ4bUZ0N0piQktIS2pjRjJTMUhZNVNkOEMzWlp5ZTFmQnVEVTVOZnNoYw==..1f6htdgom.1f6htgqqm.4r.0.4r',
}
data = '{"PostHashHex":"","ReaderPublicKeyBase58Check":"BC1YLiUgto51FaPyCPwf2LGGQcCo4qa3XM3KY1zAbK8jCzaDCc4bU27","OrderBy":"newest","StartTstampSecs":null,"PostContent":"","NumToFetch":400,"FetchSubcomments":false,"GetPostsForFollowFeed":false,"GetPostsForGlobalWhitelist":false,"GetPostsByClout":false,"PostsByCloutMinutesLookback":0,"AddGlobalFeedBool":false}'
response = requests.post('http://144.126.138.12:17001/api/v0/get-posts-stateless', headers=headers, data=data)
print(response.text)
为什么会发生这种情况?我该如何让我的Python代码工作?
我运行确切的代码,并在大约20秒后得到(相当大的)响应。
响应的长度太大,无法发布,为2067812
个字符。
与较慢的连接(我使用宽带下载2Mb每秒),这将需要更长的时间,这可能就是为什么你得到没有响应或它似乎挂起。
我添加了这段代码,并将只需几秒钟运行的文本
替换为状态_code
。试试这个:
import requests
import time
t1 = time.time()
headers = {
'authority': 'bitclout.com',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
'accept': 'application/json, text/plain, */*',
'sec-ch-ua-mobile': '?1',
'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Mobile Safari/537.36',
'content-type': 'application/json',
'origin': 'https://bitclout.com',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'accept-language': 'en-US,en;q=0.9',
'cookie': 'datadome=2P0n.mJzUY2hB5B03Tc2hild-xu2AkuX~-mIgJ2VRW-j35yl3njRPJEKTAHgcxyQdxrX-E3vQnr5GSEA~DfK3nyrtPJB1M77Ndccn3BZnf; INGRESSCOOKIE=389b5e3fc60c40d6115364749da12fd0; amp_23345b=c6QQHrpE_pvlOyAXAEKiaE.QkMxWUxpRWIzMVVHWHZ4bUZ0N0piQktIS2pjRjJTMUhZNVNkOEMzWlp5ZTFmQnVEVTVOZnNoYw==..1f6htdgom.1f6htgqqm.4r.0.4r',
}
data = '{"PostHashHex":"","ReaderPublicKeyBase58Check":"BC1YLiUgto51FaPyCPwf2LGGQcCo4qa3XM3KY1zAbK8jCzaDCc4bU27","OrderBy":"newest","StartTstampSecs":null,"PostContent":"","NumToFetch":400,"FetchSubcomments":false,"GetPostsForFollowFeed":false,"GetPostsForGlobalWhitelist":false,"GetPostsByClout":false,"PostsByCloutMinutesLookback":0,"AddGlobalFeedBool":false}'
response = requests.post('http://144.126.138.12:17001/api/v0/get-posts-stateless', headers=headers, data=data)
t2 = time.time()
print(response.status_code)
print('time taken:', round(t2-t1, 2), 'seconds')
答复:
200
time taken: 3.93 seconds
你能试试这样的数据吗:
data = "{\"PostHashHex\":\"\",\"ReaderPublicKeyBase58Check\":\"BC1YLiUgto51FaPyCPwf2LGGQcCo4qa3XM3KY1zAbK8jCzaDCc4bU27\",\"OrderBy\":\"newest\",\"StartTstampSecs\":null,\"PostContent\":\"\",\"NumToFetch\":400,\"FetchSubcomments\":false,\"GetPostsForFollowFeed\":false,\"GetPostsForGlobalWhitelist\":false,\"GetPostsByClout\":false,\"PostsByCloutMinutesLookback\":0,\"AddGlobalFeedBool\":false}"
不确定是否“内容安全策略:页面的设置阻止了在https://localhost:5000/favicon.ico(”default-src“)加载资源。”会影响。我试图使用network选项卡查看此请求,但我收到了这条消息。 它还使用Swagger UI工作:https://Swagger.io/tools/swagger-ui/
我到处都搜索了,但找不到答案,我怎么能发出HTTP请求?我尝试了几种可能性,但都不起作用。我总是出错。 02-27 17:52:58.611 13571-13571/com.example.app E/AndroidRuntime﹕ 致命异常:主java.lang.IllegalStateException:无法在android.view.view$1.onClick(view.java:3838
问题内容: 由于jQuery中的Ajax请求,存在未定义的错误。但是它在本地工作。jquery1.3.2.js @ 3633行中的错误引用 我的代码是: 代码中的警报向我显示(0,“未定义”); 我做错了什么? 问题答案: 如果您的ajax请求在完成之前被取消,则可能会发生这种情况。当用户通过刷新,单击链接或更改浏览器中的URL离开页面时,jQuery引发错误事件。通过为ajax调用实现错误处理程
但当我运行它时,它会给我这个错误: E/AndroidRuntime:致命异常:主进程:com.example.webTestConnection,PID:23550 Android.os.networkonMaintHreadexception,Android.os.strictmode$AndroidBlockGuardPolicy.onNetwork(strictmode.java:1166
这是我得到的错误: 通用域名格式。谷歌。格森。JsonSyntaxException:java。lang.IllegalStateException:应为BEGIN_对象,但在第1行第1列路径处为字符串$ 我从邮递员那里得到的JSON回复: 这就是我如何响应rest API(使用slim2框架)的响应: 回声响应方法: 调用API的方法: APIServie界面: 我如何获得实例: 我发布所有这些
请求在Postman/Java中失败,但在RESTClient中工作…以下是请求,并附上错误的截图。 这是一个POST请求 {“username”:“test”,“password”:“test”,“simulate_user”:“test”,“sourcetabledesc”:“testlist100”,“联系人”:[{“组织”:“ckt”,“workphone”:“12315423”,“fir