草庐IT

requests3

全部标签

python - urllib2 HTTP 错误 400 : Bad Request

我有一段这样的代码host='http://www.bing.com/search?q=%s&go=&qs=n&sk=&sc=8-13&first=%s'%(query,page)req=urllib2.Request(host)req.add_header('User-Agent',User_Agent)response=urllib2.urlopen(req)当我输入一个多于一个单词的查询时,例如“thedog”,我收到以下错误。response=urllib2.urlopen(req)File"/usr/lib/python2.7/urllib2.py",line126,inur

python - 用什么命令代替 urllib.request.urlretrieve?

我目前正在编写一个从URL下载文件的脚本importurllib.requesturllib.request.urlretrieve(my_url,'my_filename')文档urllib.request.urlretrieve状态:ThefollowingfunctionsandclassesareportedfromthePython2moduleurllib(asopposedtourllib2).Theymightbecomedeprecatedatsomepointinthefuture.因此我想避免它,因此我不必在不久的将来重写此代码。我在标准库中找不到像downloa

Python瓶模块导致 "Error: 413 Request Entity Too Large"

使用Python的模块bottle,我在发布正文大小的请求时遇到HTTP413错误>bottle的内部MEMFILE_MAX常量。最小的工作示例如下所示。服务器部分(server.py):frombottleimport*@post('/test')deftest():returnstr(len(request.forms['foo']));defmain():run(port=8008);if__name__=='__main__':main();客户端部分(client.py):importrequestsdefmain():url='http://127.0.0.1:8008/t

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 2.7.10 错误 "from urllib.request import urlopen"没有名为请求的模块

我从github打开了python代码。我以为它是python2.x并在我尝试运行它时出现上述错误。从阅读中我看到Python3已经贬低了urllib本身,并将其替换为包括urllib.request在内的许多库。看起来代码是用python3编写的(如果知道的人确认一下,将不胜感激。)在这一点上,我不想迁移到Python3——我还没有研究过它会对我现有的代码做什么。认为Python2应该有一个urllib模块,我搜索了谷歌(使用“python2urllib下载”)并没有找到。(由于urllib包含下载功能,它可能已隐藏在许多答案中。)我查看了我的Python27/lib目录,但在那里没

python - flask 错误 : "Method Not Allowed The method is not allowed for the requested URL"

每当我尝试将数据提交到我的Flask表单时,我都会收到以下错误:MethodNotAllowedThemethodisnotallowedfortherequestedURL.我认为问题出在我正在做的returnredirect(url_for('database'))中。我也尝试过returnrender_template('database.html)。将表单条目提交到数据库后,我正在尝试调用数据库页面。我的代码相关部分如下:@app.route('/entry',methods=['GET','POST'])defentry_page():ifrequest.method=='P

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