Search code examples
pythongoogle-app-enginewebapp2

Regex to extract URI arguments such as URL's in webapp2 (Python)?


In routes.py, I've tried below code (not a regex expert) and intend to pass http/https links in url_arg e.g. http://google.com or https://google.com.

r'/some_api/<url_arg:.*>'

Here is the error for localhost:8080/some_api/https://google.com or localhost:8080/some_api/http://google.com

Traceback (most recent call last):
  File "/google-cloud-sdk/platform/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 1292, in communicate
    req.parse_request()
  File "/google-cloud-sdk/platform/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 580, in parse_request
    success = self.read_request_line()
  File "/google-cloud-sdk/platform/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 643, in read_request_line
    scheme, authority, path = self.parse_request_uri(uri)
  File "/google-cloud-sdk/platform/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 805, in parse_request_uri
    authority, path = remainder.split(FORWARD_SLASH, 1)
ValueError: need more than 1 value to unpack

Solution

  • looks like this is a bug in cherrypy, which app engine's devappserver2 uses. details: https://code.google.com/archive/p/appengine-devappserver2-experiment/issues/69

    (i have the same problem, and don't have a good fix or workaround yet.)