草庐IT

Requests库

全部标签

java - 改造 2/OkHttp : Cancel all running requests

我正在使用带有OkHttp2.7.0的Retrofit2-beta2。要从Retrofit获取OkHttpClient对象,我使用Retrofit.client()方法并取消所有正在运行的请求,我称之为cancel(Objecttag)方法,但请求仍在运行,我得到了响应。甚至客户端的Dispatcher的getQueuedCallCount()和getRunningCallCount()调用cancel()后返回0。我还需要做些什么才能让它发挥作用吗?或者它可能是OkHttp中的错误?作为解决方法,我在客户端的ExecutorService上调用shutdownNow(),但我更喜欢更

python - 名称错误 : name 'requests' is not defined

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭8年前。Improvethisquestion我已将此代码作为帮助“Pythongettingalllinksfromagooglesearchresultpage”。当我尝试在Python3.3.3中导入请求时,我得到NameError:name'requests'isnotdefined。我使用CMD提示符测试了“request”和“bs4

python - 尝试在 mac OS 中运行此命令 "pipenv install requests "时出错

我遇到了以下错误:Warning:theenvironmentvariableLANGisnotset!Werecommendsettingthisin~/.profile(orequivalent)forproperexpectedbehavior.Creatingavirtualenvforthisproject…Using/usr/local/opt/python/bin/python3.6(3.6.4)tocreatevirtualenv…⠋Traceback(mostrecentcalllast):File"/usr/local/Cellar/python/3.6.4_4/F

django - python-requests 和 django - CSRF 验证失败。请求中止

我有一个django服务器来上传文件,当我使用浏览器时,我可以毫无问题地上传文件。但是如果我使用python-requests命令,它会告诉我CSRF验证失败。请求中止。python-requests代码如下:#uploadviaHTTPfile={"docfile":open(fullfilename,"rb")}s=requests.Session()r=s.get(dhost)r=s.post(dhost,files=file)如果我执行我的代码,我得到代码403并且错误CSRF验证失败。请求中止。失败原因:CSRFtokenmissingorincorrect.但是如果我查看我

python - 如何使 requests_cache 与许多并发请求一起工作?

我正在获取并缓存(为了性能)很多URL,例如:importrequestsimportrequests_cachefrommultiprocessing.poolimportThreadPoolurls=['http://www.google.com',...]withrequests_cache.enabled():responses=ThreadPool(100).map(requests.get,urls)但是,我遇到了很多错误:sqlite3.OperationalError:databaseislocked显然有太多线程同时访问缓存。requests_cache也是如此支持某

python - 使用 python-requests 压缩请求体?

(这个问题不是关于gzip编码的responses来自网络服务器的透明解压;我知道requestshandlesthatautomatically。)问题我正在尝试将文件发布到RESTful网络服务。显然,requests使这很容易做到:files=dict(data=(fn,file))response=session.post(endpoint_url,files=files)在这种情况下,我的文件采用高度可压缩的格式(是的,XML),因此我想确保压缩请求正文。服务器声称接受gzip编码(Accept-Encoding:gzip在响应header中),所以我应该能够gzip整个请求

python - 如何在不写入磁盘的情况下使用 Python-Requests 上传文本文件

我想在Python3中使用Python的Requests库在POST请求中发送一个文件。我正在尝试像这样发送它:importrequestsfile_content='Thisisthetextofthefiletoupload'r=requests.post('http://endpoint',params={'token':'api_token','message':'messagetext',},files={'filename':file_content},)但是,服务器响应没有发送任何文件。这应该工作吗?大多数示例涉及传递一个文件对象,但我不想为了上传它而将字符串写出到磁盘。

python - requests.get() (Python,请求模块)是否暂停脚本直到响应到达?

这个问题是关于Python的Requests模块。我正在使用requests.get()并遇到一个问题,我超出了我所联系的服务器允许我的请求速率限制。我在每个requests.get()之后设置了一个time.sleep()到一个更大的数量级。代码是这样的:forurlinurl_list:success=Falseresponse=requests.get(url)whilenotsuccess:time.sleep(1/250)ifstr(response)=="":time.sleep(1/250)#WaitXsbetweenAPIcalldo_stuff(response.te

python-requests - 用户代理被覆盖

我有logindata={'username':'me','password':'blbla'}payload={'from':'me','lang':'en','url':csv_url}headers={'User-Agent':'Mozilla/5.0'}api_url='http://dev.mypage.com/admin/app/import/'withrequests.Session()ass:s.post(api_url,data=json.dumps(logindata),headers=headers)prints.headers#Anauthorisedreque

python - 使用 Requests 和 Django 从脚本登录网页

我用Django编写了一个Web应用程序。我需要将一些数据从python脚本发布到表单。禁用登录后,帖子(r2)可以正常工作。我的登录请求(r1)可以正常工作,但它现在为表单发布(r2)提供了404错误。登录似乎没有转移到第二个请求。csrftoken和sessionid被硬编码用于测试,因为它无法识别它们。相关代码(去掉urlbase):url_login='../pecasRunLog/accounts/login/'url_add_run='../pecasRunLog/model/'+region+'/add_run/'client=requests.session()clie