2013-07-08 50 views
2

我有一個用python編寫的網站,它運行在Google App Engine上。我需要通過代理獲取網址。如何在Google App Engine上通過代理獲取網址?

閱讀文檔說,我應該能夠使用urllib2來做到這一點,但似乎應該工作,不是。

import urllib2, urllib 

proxy = urllib2.ProxyHandler({'http': 'http://username:[email protected]:port'}) 
auth = urllib2.HTTPBasicAuthHandler() 
opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) 
urllib2.install_opener(opener) 

conn = urllib2.urlopen('http://icanhazip.com/') 
print conn.read() 

在我的本地開發中運行上述代碼返回我的IP。在網站上執行相同的代碼會返回Google使用的8.35.201.X地址之一。這幾乎就像ProxyHandler被忽略了一樣。

任何幫助將不勝感激。

回答

1

您無法使用代理在GAE上發出請求。

至少對於Java來說是這樣(今天掙扎着,Google故意限制這個)。我很確定這也是Python的情況。

相關問題