[英]dev-server HTTP Error 403: Forbidden
從1.7.5更新(一切正常)我得到一個HTTP錯誤403:禁止嘗試通過localhost打開任何網站。 奇怪的是我在家里的設置幾乎和在這里工作一樣,一切都在那里工作......可能是我們在工作中使用的代理服務器的問題,因為這是我能想到的唯一區別? 這是我得到的錯誤日志,所以如果有人知道發生了什么,請幫助(;
Traceback (most recent call last):
File "U:\Dev\GAE\lib\cherrypy\cherrypy\wsgiserver\wsgiserver2.py", line 1302, in communicate
req.respond()
File "U:\Dev\GAE\lib\cherrypy\cherrypy\wsgiserver\wsgiserver2.py", line 831, in respond
self.server.gateway(self).respond()
File "U:\Dev\GAE\lib\cherrypy\cherrypy\wsgiserver\wsgiserver2.py", line 2115, in respond
response = self.req.server.wsgi_app(self.env, self.start_response)
File "U:\Dev\GAE\google\appengine\tools\devappserver2\wsgi_server.py", line 246, in __call__
return app(environ, start_response)
File "U:\Dev\GAE\google\appengine\tools\devappserver2\request_rewriter.py", line 311, in _rewriter_middleware
response_body = iter(application(environ, wrapped_start_response))
File "U:\Dev\GAE\google\appengine\tools\devappserver2\python\request_handler.py", line 89, in __call__
self._flush_logs(response.get('logs', []))
File "U:\Dev\GAE\google\appengine\tools\devappserver2\python\request_handler.py", line 220, in _flush_logs
apiproxy_stub_map.MakeSyncCall('logservice', 'Flush', request, response)
File "U:\Dev\GAE\google\appengine\api\apiproxy_stub_map.py", line 94, in MakeSyncCall
return stubmap.MakeSyncCall(service, call, request, response)
File "U:\Dev\GAE\google\appengine\api\apiproxy_stub_map.py", line 320, in MakeSyncCall
rpc.CheckSuccess()
File "U:\Dev\GAE\google\appengine\api\apiproxy_rpc.py", line 156, in _WaitImpl
self.request, self.response)
File "U:\Dev\GAE\google\appengine\ext\remote_api\remote_api_stub.py", line 200, in MakeSyncCall
self._MakeRealSyncCall(service, call, request, response)
File "U:\Dev\GAE\google\appengine\ext\remote_api\remote_api_stub.py", line 226, in _MakeRealSyncCall
encoded_response = self._server.Send(self._path, encoded_request)
File "U:\Dev\GAE\google\appengine\tools\appengine_rpc.py", line 393, in Send
f = self.opener.open(req)
File "U:\Dev\Python\lib\urllib2.py", line 410, in open
response = meth(req, response)
File "U:\Dev\Python\lib\urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "U:\Dev\Python\lib\urllib2.py", line 448, in error
return self._call_chain(*args)
File "U:\Dev\Python\lib\urllib2.py", line 382, in _call_chain
result = func(*args)
File "U:\Dev\Python\lib\urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden
INFO 2013-04-19 12:28:52,576 server.py:561] default: "GET / HTTP/1.1" 500 -
INFO 2013-04-19 12:28:52,619 server.py:561] default: "GET /favicon.ico HTTP/1.1" 304 -
此外,啟動器在關閉時拋出錯誤:
Traceback (most recent call last):
File "launcher\mainframe.pyc", line 327, in OnStop
File "launcher\taskcontroller.pyc", line 167, in Stop
File "launcher\dev_appserver_task_thread.pyc", line 82, in stop
File "launcher\taskthread.pyc", line 107, in stop
File "launcher\platform.pyc", line 397, in KillProcess
pywintypes.error: (5, 'TerminateProcess', 'Access is denied.')
當使用使用Google App Engine Launcher 1.8.6的代理服務器時,我的MacOSX遇到了同樣的問題。 顯然“urllib2.py”上的“proxy_bypass”存在問題。
有兩種可能的解決方案:
修改“[GAE Instalattion path] /google/appengine/tools/appengine_rpc.py”並查找說明的行
opener.add_handler(fancy_urllib.FancyProxyHandler())
在我的計算機中它是第578行,然后在行的開頭放一個哈希(#),如下所示:
`#opener.add_handler(fancy_urllib.FancyProxyHandler())`
保存文件,停止然后重新啟動應用程序。 現在dev_appserver.py根本不應該嘗試使用任何代理服務器。
如果您的應用程序使用任何外部資源(如SOAP Web服務或類似的東西),並且您無法在沒有代理服務器的情況下訪問服務器,那么您將不得不降級。 請記住,外部JavaScript文件(如facebook SDK或類似文件)是從您的瀏覽器加載的,而不是從您的應用程序加載的。
由於我沒有使用任何外部REST或SOAP服務,它對我有用!
希望它也適合你。
嘗試執行以下任一操作: - 通過其他代理訪問它。 IE瀏覽器 代理中的代理 - 通過本地IP即192.168.1.1訪問它
版本1.9.5我遇到了同樣的問題。 似乎API代理正在向代理服務器發送一些RPC,然后使用HTTP 403拒絕這些RPC(因為代理服務器通常配置為拒絕對任意端口的連接嘗試)。 在我的情況下,我在我的應用程序中使用urlfetch
模塊來訪問外部網頁,因此禁用代理服務器對我來說不是一個選擇。
這就是我在一段時間內解決這個問題的方法(很可能是基於這個問題下的評論,但我記不清確切的來源)。
注意:
在這里:
以某種方式禁用Python(Google App Engine Launcher)環境的代理設置。 (在我的例子中,因為我從終端shell(在Linux上)啟動了dev_appserver.py
,所以很容易,並且未unset http_proxy
和未unset https_proxy
命令就可以了。)
修改{App Engine SDK root}/google/appengine/api/urlfetch_stub.py
。 找到代碼塊
if _CONNECTION_SUPPORTS_TIMEOUT: connection = connection_class(host, timeout=deadline) else: connection = connection_class(host)
(在我的案例中為第376-379行)並將其替換為:
if _CONNECTION_SUPPORTS_TIMEOUT: if host[:9] == 'localhost' or host[:9] == '127.0.0.1': connection = connection_class(host, timeout=deadline) else: connection = connection_class('your_proxy_host_goes_here', your_proxy_port_number_goes_here, timeout=deadline) else: if host[:9] == 'localhost' or host[:9] == '127.0.0.1': connection = connection_class(host) else: connection = connection_class('your_proxy_host_goes_here', your_proxy_port_number_goes_here)
用適當的值替換占位符your_proxy_host_goes_here
和your_proxy_port_number_goes_here
。
(我相信這段代碼可以寫得更優雅,但是......任何Python極客都在那里?:))
在我的情況下,我還必須刪除現有的編譯文件urlfetch_stub.pyc
(位於與urlfetch_stub.py
相同的目錄中),因為在我這樣做之前SDK似乎沒有接收到更改。
現在您可以使用dev_appserver
啟動您的應用程序,並在應用程序中使用urlfetch
-backed服務,不會出現HTTP 403錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.