2014-02-21 80 views
1

我剛開始使用python 3.3.3中的urllib,我可以使用urllib.request.urlopen()來發出POST請求。但是,我想要做的是使用HTTPS的POST。我看到urlopen的文檔中提到「目前HTTP請求是唯一使用數據的請求」(並且我需要POST請求的'data'參數)。Python3 urllib POST和HTTPS

然後,我看到urllib.request.HTTPSHandler似乎能夠通過其https_open()進行HTTPS POST。不幸的是,我似乎無法弄清楚如何使用這個功能。現在,我只想做一個簡單的HTTPS與此處理程序GET,所以我試圖做的是

import urllib.request 
r = urllib.request.Request("https://www.google.com") 
handler = urllib.request.HTTPSHandler() 
handler.https_open(r) 

但是這會導致AttributeError: 'Request' object has no attribute 'timeout'

我怎樣才能得到HTTPSHandler.https_open()工作?或者根本urlopen調用https_open功能,如果我用

opener = urllib.request.build_opener(urllib.request.HTTPSHandler) 
urllib.request.install_opener(opener) 

,實際上確實讓HTTPS POST請求了嗎?謝謝!

回答

0

嘗試使用data=Noneurlopen

或者使用Requests

+0

嗨,我在帖子中說我需要的「數據」的參數,因爲我必須做一個POST請求。沒有數據,我只能做出GET請求。 – user1448268