2013-11-24 54 views
0

此問題之前已被詢問,但未找到可行的答案!urlfetch無法在GAE中獲取URL

我在我的代碼中使用urlfetch來獲取url內容,但無法獲取URL錯誤。繼承人我的代碼部分:

import cgi 
import webapp2 
from google.appengine.api import urlfetch 

class MainPage(webapp2.RequestHandler): 
    def get(self): 
     self.response.write(MAIN_PAGE_HTML) # MAIN_PAGE_HTML is defined .. 
class Hunt(webapp2.RequestHandler): 
    def flip(self): 
     page=urlfetch.fetch('http://103.4.253.46/search?q=nexus 4') 

#<////Rest Of the Code  /////>  

我收到內部服務器錯誤,這

Traceback (most recent call last): 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__ 
    rv = self.handle_exception(request, response, e) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__ 
    rv = self.router.dispatch(request, response) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher 
    return route.handler_adapter(request, response) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__ 
    return handler.dispatch() 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch 
    return self.handle_exception(e, self.app.debug) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch 
    return method(*args, **kwargs) 
    File "/base/data/home/apps/s~dime-hunt/1.371847514565231627/hunt.py", line 61, in post 
    self.flip() 
    File "/base/data/home/apps/s~dime-hunt/1.371847514565231627/hunt.py", line 39, in flip 
    page=urlfetch.fetch('http://103.4.253.46/search?q=nexus 4') 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/urlfetch.py", line 270, in fetch 
    return rpc.get_result() 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 612, in get_result 
    return self.__get_result_hook(self) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/urlfetch.py", line 403, in _get_fetch_result 
    raise DownloadError("Unable to fetch URL: " + url + error_detail) 
DownloadError: Unable to fetch URL: http://103.4.253.46/search?q=nexus 4 

我更換了網站名稱與ip地址,但仍是同樣的錯誤。 我能夠使用請求在本地在IDLE中進行測試時從站點獲取數據。

+2

是它的建議,因爲你有關係和4,而不是「%20」之間的空間? – Back2Basics

+0

@ Back2Basics奇怪,但它的工作!謝謝 –

回答

0
'http://103.4.253.46/search?q=nexus%204' 

通過更換20%的空間解決了這個錯誤由​​@ Back2Basics