我有一個Python腳本用於連接到Parse.com(遠程服務器)並上傳文件。該腳本運行位於企業防火牆後面的服務器。請求庫中的代理設置Python
import env
import json
import requests
from requests.auth import HTTPProxyAuth
def uploadFile(fileFullPath):
print "Attempting to upload file: " + fileFullPath
proxies = {
"http": "http://10.128.198.14",
"https": "http://10.128.198.14"
}
auth = HTTPProxyAuth('MyDomain\MyUsername', 'MyPassord')
headers = {
"X-Parse-Application-Id": env.X_Parse_APP_ID,
"X-Parse-REST-API-Key": env.X_Parse_REST_API_Key,
"Content-Type": "application/pdf"
}
f = open(fileFullPath, 'r')
files = {'file': f}
r = requests.post(env.PARSE_HOSTNAME + env.PARSE_FILES_ENDPOINT + "/" + env.PARSE_FILE_NAME, files=files, headers=headers, timeout=10, verify=False, proxies=proxies)
print r.text
當我用這個模塊在命令提示符下,我得到了以下信息:
ConnectionError thrown. Details: Cannot connect to proxy. Socket error: Tunnel connection failed: 407 Proxy Authentication Required.
我敢肯定的用戶名和密碼都是正確的。
任何解決方案?謝謝!
您沒有爲'requests.post()'方法提供'auth'參數 – JRodDynamite
我向requests.post()添加了「auth」,但由於同樣的錯誤,它仍然失敗... – alextc