我想把一個文件放到WebDav啓用的URL。 的代碼看起來是這樣的:蟒蛇3得到401使用requests.put
headers = {'Authorization':'Basic', 'username': 'doc_iconx', 'password': 'doc_iconx'}
id = "SOMEID"
pw = "SOMEPW"
try:
url = 'https://mywebsite.com/Dir/'
files = {'upload_file': open(fileName, 'rb')}
r = requests.put(url,auth=HTTPDigestAuth(id,pw), files=files, headers={'User-Agent': 'Mozilla'
})
我回去:
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>
我知道ID /密碼是好的,因爲我可以使用curl
任何想法做一個放?
從我看到的情況來看,您應該使用'HTTPBasicAuth'而不是'HTTPDigestAuth'。你也提到'post',但在你的例子中你正在做一個'put'。 – sal
感謝您指出我的錯字。我糾正了描述爲.put。 – user3670332
嘗試使用HTTPBasicAuth。現在我得到了:409客戶端錯誤:URL衝突:https://content-qa.homedepot.com/IconX/Report/ – user3670332