2017-03-28 68 views
1

我有蟒蛇的工作守則,文件上載到服務器與下面的代碼[R HTTR錯誤403

with open(file_path, 'rb') as fp: 
    r = requests.Request('PUT', signedRequest, data=fp.read()) 
    prepped = r.prepare() 
    s = requests.Session() 
    resp = s.send(prepped) 

在RI現在用的是下面的代碼,因爲它是替代

PUT(url = signedRequest, 
    body = upload_file(path = file_path),verbose() 
    ) 

但它是拋出錯誤

HTTP/1.1 403 Forbidden 

在requestbin請求被接收爲

對於Python

Cf-Connecting-Ip: **** 
Host: requestb.in 
Connect-Time: 1 
Total-Route-Time: 0 
Via: 1.1 vegur 
Content-Length: 6481350 
Connection: close 
Cf-Ipcountry: US 
X-Request-Id: f9b165cc-0f42-4eaa-8b40-2eb37a6ff1ca 
Accept-Encoding: gzip 
Cf-Ray: 346d734353e871df-ORD 
Cf-Visitor: {"scheme":"http"} 

當R

Cf-Connecting-Ip: **** 
Content-Length: 6481350 
User-Agent: libcurl/7.47.0 r-curl/2.3 httr/1.2.1 
Total-Route-Time: 0 
Via: 1.1 vegur 
Connection: close 
Cf-Ipcountry: US 
Content-Type: text/csv 
X-Request-Id: 0bfbf6ab-4658-4650-bd4d-e1e19ffdba91 
Accept: application/json, text/xml, application/xml, */* 
Connect-Time: 0 
Accept-Encoding: gzip 
Host: requestb.in 
Cf-Ray: 346d6e90d70f54ec-ORD 
Cf-Visitor: {"scheme":"http"} 

有什麼建議?

+0

而不是張貼到真實的URL抑制用戶代理,您可以嘗試在Python和R等網站上發佈https://requestb.in/,以比較服務器看到的請求。您正在嘗試上傳的文件類型是什麼? – MrFlick

+0

我想上傳一個.csv文件 – anonR

+0

發佈了兩個輸出。 – anonR

回答

1

很難說服務器在抱怨什麼,但是如果我們比較兩個請求,我們看到內容類型和用戶代理存在差異。

您可以

upload_file(path = file_path, type="") 

打壓內容類型可以通過同時傳遞

user_agent("") 

作爲參數傳遞給PUT()