经过多次尝试和反复失败后,我在这里发布了我的代码摘录。我不断收到身份验证失败。有人能指出我在这里做错了什么吗?
import requests
fileToUpload = {'file': open('/home/pinku/Desktop/Test_Upload.odt', 'rb')}
res = requests.post('https://upload.backupgrid.net/add', fileToUpload)
print res.headers
cookie = {'PHPSESSID': 'tobfr5f31voqmtdul11nu6n9q1'}
requests.post('https://upload.backupgrid.net/add', cookie, fileToUpload)
通过打印res.headers,我得到以下内容:
CaseInsensitiveDict({'content-length':'67', 'access-control-allow-methods':'OPTIONS,HEAD,GET,POST,PUT, DELETE','x-content-type-options':'nosniff','content-encoding': 'gzip','set-cookie':'PHPSESSID = ou8eijalgpss204thu7ht532g1;路径= /, B100Serverpoolcookie = 4281246842.1.973348976.502419456;路径= /”, 'expires':'星期四,1981年11月19日08:52:00 GMT','变化':'接受编码', 'server':'Apache / 2.2.15(CentOS)','pragma':'no-cache', 'cache-control':'no-store,no-cache,must-revalidate','date':'Mon, 2013年9月9日09:13:08 GMT','access-control-allow-origin':'*', 'access-control-allow-headers':'X-File-Name,X-File-Type, X-File-Size','content-type':'text / html;字符集= UTF-8' })
它还包含cookie。我正确地传递了cookie吗?请帮忙!
答案 0 :(得分:1)
您没有正确传递Cookie,应该是:
requests.post('https://upload.backupgrid.net/add',
files=fileToUpload,
cookies=cookie)
另见文件: