我在我的代码中使用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
我用ipaddress替换了网站名称,但仍然是同样的错误。 我可以在IDLE本地测试时使用请求从站点获取数据。
答案 0 :(得分:0)
'http://103.4.253.46/search?q=nexus%204'
用%20替换空格解决了@ Back2Basics
建议的错误