Flask蓝图如何调试路由

时间:2014-12-30 08:36:40

标签: python debugging flask blueprint

我有一个暴露api的烧瓶应用程序。

当我从浏览器http://admin.phones.dev/api/v2.0/manufacturers点击此API时,我获得状态200并按预期响应。请求对象:

{
   'view_args':{},
   'cookies':{
      'session':u'eyJfaWQiOnsiIGIiOiJPREJsTURrNFlUZGtNRFkzWVdKbU1XRmlNalJpTldZelkySmhaVGhtT1RjPSJ9fQ.B4PxFw.4ytdqip7jIF3WJLqKyItDf8Cuu0'
   },
   'shallow':False,
   'url_rule':<Rule '/manufacturers/' (HEAD, OPTIONS, GET) -> manufacturers.index>,
   'headers':EnvironHeaders(   [
      ('Cookie', u'session=eyJfaWQiOnsiIGIiOiJPREJsTURrNFlUZGtNRFkzWVdKbU1XRmlNalJpTldZelkySmhaVGhtT1RjPSJ9fQ.B4PxFw.4ytdqip7jIF3WJLqKyItDf8Cuu0'),
      ('Content-Length', u''),
      ('User-Agent', u'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0      ) Gecko/20100101 Firefox/31.0'),
      ('Connection', u'keep-alive'),
      ('Host', u'admin.phones.dev:5000'), 
      ('Cache-Control', u'max-age=0'),
      ('Accept', u'text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8'),
      ('Accept-Language', u'en-US, en;q=0.5'),
      ('Content-Type', u''),
      ('Accept-Encoding', u'gzip, deflate')
   ]   ),
   'environ':{
      'wsgi.multiprocess':False,
      'HTTP_COOKIE':'session=eyJfaWQiOnsiIGIiOiJPREJsTURrNFlUZGtNRFkzWVdKbU1XRmlNalJpTldZelkySmhaVGhtT1RjPSJ9fQ.B4PxFw.4ytdqip7jIF3WJLqKyItDf8Cuu0',
      'SERVER_SOFTWARE':'Werkzeug/0.9.4',
      'SCRIPT_NAME':'/api/v2.0',
      'REQUEST_METHOD':'GET',
      'PATH_INFO':'/manufacturers',
      'SERVER_PROTOCOL':'HTTP/1.1',
      'QUERY_STRING':'',
      'werkzeug.server.shutdown':<function shutdown_server at 0xb54a472c>,
      'CONTENT_LENGTH':'',
      'HTTP_USER_AGENT':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0',
      'HTTP_CONNECTION':'keep-alive',
      'SERVER_NAME':'0.0.0.0',
      'REMOTE_PORT':45113,
      'wsgi.url_scheme':'http',
      'SERVER_PORT':'5000',
      'werkzeug.request':      <Request 'http:      //admin.phones.dev:5000      /api/v2.0/manufacturers'      [
         GET
      ]      >,
      'wsgi.input':<socket._fileobject object at 0xb549a5ec>,
      'HTTP_HOST':'admin.phones.dev:5000',
      'wsgi.multithread':False,
      'HTTP_CACHE_CONTROL':'max-age=0',
      'HTTP_ACCEPT':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
      'wsgi.version':(1, 0),
      'wsgi.run_once':False,
      'wsgi.errors':<open file '<stderr>', mode 'w' at 0xb751b0d0>,
      'REMOTE_ADDR':'192.168.33.1',
      'HTTP_ACCEPT_LANGUAGE':'en-US,en;q=0.5',
      'CONTENT_TYPE':'',
      'HTTP_ACCEPT_ENCODING':'gzip, deflate'
   }
}

现在我已经获得了WordPress应用,并且我尝试使用wp_remote_get()连接到此api。我可以看到该请求命中烧瓶应用程序但由于某种原因它返回404.再次请求对象:

{
   'headers':EnvironHeaders(   [
      ('Content-Length', u''),
      ('User-Agent', u'WordPress/3.9.1; http://cbp-v2.localhost.com'),
      ('Host', u'admin.phones.dev'),
      ('Content-Type', u''),
      ('Accept-Encoding', u'deflate;q=1.0, compress;q=0.5, gzip;q=0.5')
   ]   ),
   'cookies':{

   },
   'shallow':False,
   'environ':{
      'wsgi.multiprocess':False,
      'SERVER_SOFTWARE':'Werkzeug/0.9.4',
      'SCRIPT_NAME':'/api/v2.0',
      'REQUEST_METHOD':'GET',
      'PATH_INFO':'/manufacturers',
      'SERVER_PROTOCOL':'HTTP/1.0',
      'QUERY_STRING':'',
      'werkzeug.server.shutdown':<function shutdown_server at 0xb54a479c>,
      'CONTENT_LENGTH':'',
      'HTTP_USER_AGENT':'WordPress/3.9.1; http://cbp-v2.localhost.com',
      'SERVER_NAME':'0.0.0.0',
      'REMOTE_PORT':45115,
      'wsgi.url_scheme':'http',
      'SERVER_PORT':'5000',
      'werkzeug.request':      <Request 'http://admin.phones.dev/api/v2.0/manufacturers'      [
         GET
      ]      >,
      'wsgi.input':<socket._fileobject object at 0xb549a72c>,
      'HTTP_HOST':'admin.phones.dev',
      'wsgi.multithread':False,
      'wsgi.version':(1, 0),
      'wsgi.run_once':False,
      'wsgi.errors':<open file '<stderr>', mode 'w' at 0xb751b0d0>,
      'REMOTE_ADDR':'192.168.33.1',
      'CONTENT_TYPE':'',
      'HTTP_ACCEPT_ENCODING':'deflate;q=1.0, compress;q=0.5, gzip;q=0.5'
   },
   'url':   u'http://admin.phones.dev/api/v2.0/manufacturers',
   'shallow':False,
   'headers':EnvironHeaders(   [
      ('Content-Length', u''),
      ('User-Agent', u'WordPress/3.9.1; http://cbp-v2.localhost.com'),
      ('Host', u'admin.phones.dev'),
      ('Content-Type', u''),
      ('Accept-Encoding', u'deflate;q=1.0, compress;q=0.5, gzip;q=0.5')
   ]   ),
   'environ':{
      'wsgi.multiprocess':False,
      'SERVER_SOFTWARE':'Werkzeug/0.9.4',
      'SCRIPT_NAME':'/api/v2.0',
      'REQUEST_METHOD':'GET',
      'PATH_INFO':'/manufacturers',
      'SERVER_PROTOCOL':'HTTP/1.0',
      'QUERY_STRING':'',
      'werkzeug.server.shutdown':<function shutdown_server at 0xb54a479c>,
      'CONTENT_LENGTH':'',
      'HTTP_USER_AGENT':'WordPress/3.9.1; http://cbp-v2.localhost.com',
      'SERVER_NAME':'0.0.0.0',
      'REMOTE_PORT':45115,
      'wsgi.url_scheme':'http',
      'SERVER_PORT':'5000',
      'werkzeug.request':      <Request 'http://admin.phones.dev/api/v2.0/manufacturers'      [
         GET
      ]      >,
      'wsgi.input':<socket._fileobject object at 0xb549a72c>,
      'HTTP_HOST':'admin.phones.dev',
      'wsgi.multithread':False,
      'wsgi.version':(1, 0),
      'wsgi.run_once':False,
      'wsgi.errors':<open file '<stderr>', mode 'w' at 0xb751b0d0>,
      'REMOTE_ADDR':'192.168.33.1',
      'CONTENT_TYPE':'',
      'HTTP_ACCEPT_ENCODING':'deflate;q=1.0, compress;q=0.5, gzip;q=0.5'
   },
   'routing_exception':   <NotFound '404:Not Found'>
}

我的问题是如何调试此问题?我对python和flask来说比较新,所以任何提示都值得赞赏。

1 个答案:

答案 0 :(得分:1)

卷曲丢失了,安装后它再次起作用。