草庐IT

Requests库

全部标签

python - 如何使用 requests 库从 http 请求中获取 IP 地址?

我正在使用python中的请求库发出HTTP请求,但我需要来自响应HTTP请求的服务器的IP地址,并且我试图避免进行两次调用(并且可能与响应请求的人)。这可能吗?是否有任何pythonHTTP库允许我这样做?PS:我还需要发出HTTPS请求并使用经过身份验证的代理。更新1:例子:importrequestsproxies={"http":"http://user:password@10.10.1.10:3128","https":"http://user:password@10.10.1.10:1080",}response=requests.get("http://example.o

python - 删除错误 : 'requests' is a dependency of conda and cannot be removed from conda's operating environment

在安装第三方库时遇到问题,在使用安装了Anaconda的Windows10之前我没有看到此错误:C:\Users\XYZ>condaenvcreate-fpython3.6-environment-windows.ymlCollectingpackagemetadata:doneSolvingenvironment:doneDownloadingandExtractingPackagescertifi-2018.1.18|144KB|############################################################################|

python - pip install requests[security] vs pip install requests : Difference

我正在使用Ubuntu14.04(TrustyTahr)和Python版本2.7.6。今天,当我创建一个新的virtualenv并尝试执行pipinstallrequests时,我收到了错误InsecurePlatformWarning。我按照SSLInsecurePlatformerrorwhenusingRequestspackage中的说明解决了这个问题.但我想了解这两个命令之间的实际区别是什么:pipinstallrequests[security]和pipinstallrequests.为什么前者要额外安装三个包?当我将代码推送到生产环境时,有什么需要注意的吗?它们的行为通常

python - 如何使用 Requests 库执行 HTTP DELETE 请求

我正在使用requests用于与toggl.comAPI交互的包。我可以执行GET和POST请求:payload={'some':'data'}headers={'content-type':'application/json'}url="https://www.toggl.com/api/v6/"+data_description+".json"response=requests.post(url,data=json.dumps(payload),headers=headers,auth=HTTPBasicAuth(toggl_token,'api_token'))但我似乎找不到执行

python - 获取 Python Requests 中状态码的描述

我希望能够输入服务器响应代码并让请求告诉我代码的含义。比如code200-->ok我找到了sourcecode的链接它显示了代码和描述的字典结构。我看到请求将返回给定描述的响应代码:printrequests.codes.processing#returns102printrequests.codes.ok#returns200printrequests.codes.not_found#returns404但不是相反:printrequests.codes[200]#returnsNoneprintrequests.codes.viewkeys()#returnsdict_keys([

Python:requests.exceptions.ConnectionError。 url 超出了最大重试次数

这是脚本:importrequestsimportjsonimporturlparsefromrequests.adaptersimportHTTPAdapters=requests.Session()s.mount('http://',HTTPAdapter(max_retries=1))withopen('proxies.txt')asproxies:forlineinproxies:proxy=json.loads(line)withopen('urls.txt')asurls:forlineinurls:url=line.rstrip()data=requests.get(ur

python - 可以在 Google App Engine 上使用 Python Requests 库吗?

我可以使用Requests在谷歌应用引擎上?我认为这个库非常适合创建REST客户端。 最佳答案 安装requests-toolbelt库:https://github.com/sigmavirus24/requests-toolbelt对于AppEngine,它可能类似于:pipinstallrequests-toolbelt-tlib(参见:https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27#installing_a_libr

python - 从 Flask 返回 requests.Response 对象

我正在尝试使用Flask和请求构建一个简单的代理。代码如下:@app.route('/es///',methods=['GET','POST','PUT']):defes(index,type,id):elasticsearch=find_out_where_elasticsearch_lives()#alsohandlesomeauthenticationurl='%s%s%s%s'%(elasticsearch,index,type,id)esreq=requests.Request(method=request.method,url=url,headers=request.hea

python - 使用 python-requests 获取文件大小,同时只获取标题

我查看了请求文档,但似乎找不到任何东西。如何只请求header,以便评估文件大小? 最佳答案 发送HEADrequest:>>>importrequests>>>response=requests.head('http://example.com')>>>response.headers{'connection':'close','content-encoding':'gzip','content-length':'606','content-type':'text/html;charset=UTF-8','date':'Fri,1

python - 如何使用 requests.post (Python) 发送数组? "Value Error: Too many values to unpack"

我正在尝试使用requests.post向WheniWorkAPI发送请求数组(列表),但我不断收到两个错误之一。当我将列表作为列表发送时,我收到一个解包错误,当我将它作为一个字符串发送时,我收到一个错误,要求我提交一个数组。我认为这与请求如何处理列表有关。以下是示例:url='https://api.wheniwork.com/2/batch'headers={"W-Token":"Ilovemyboss"}data=[{'url':'/rest/shifts','params':{'user_id':0,'other_stuff':'value'},'method':'post',