dev-server HTTP Error 403: Forbidden

1 view
Skip to first unread message

Janaka Bandara via StackOverflow

unread,
Feb 15, 2015, 8:03:33 AM2/15/15
to google-appengin...@googlegroups.com

I faced the same issue with version 1.9.5. Seems that the API proxy is sending some RPCs to the proxy server, which are then being rejected with HTTP 403 (since proxy servers are generally configured to reject connection attempts to arbitrary ports). In my case I was using the urlfetch module in my app to access external web pages, so disabling the proxy server was not a choice for me.

This is how I worked around the issue some time back (most probably it was based on comments found under this issue, but I cannot remember the exact sources).

NOTE:

  • For this approach to work, you'll have to know the hostname/IP address and default port of your proxy server, and change them appropriately in the code if you happen to connect to a different proxy server.
  • When you are not behind the proxy server, you will have to revert the applied changes in order to return to a working state (if you want internet access inside your app).

Here it goes:

  1. Disable proxy settings for the Python (Google App Engine Launcher) environment in some way. (In my case it was easy since I was launching the dev_appserver.py from a Terminal shell (on Linux), and the unset http_proxy and unset https_proxy commands did the trick.)

  2. Edit {App Engine SDK root}/google/appengine/api/urlfetch_stub.py. Find the code block

    if _CONNECTION_SUPPORTS_TIMEOUT:
        connection = connection_class(host, timeout=deadline)
    else:
        connection = connection_class(host)
    

    (lines 376-379 in my case) and replace it with:

    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)
    

    replacing the placeholders your_proxy_host_goes_here and your_proxy_port_number_goes_here with appropriate values.

    (I believe this code can be written more elegantly, though... any Python geeks out there? :) )

  3. In my case, I also had to delete the existing compiled file urlfetch_stub.pyc (located in the same directory as urlfetch_stub.py) because the SDK didn't seem to pick up the changes until I did so.

Now you can use dev_appserver to launch your app, and use urlfetch-backed services within the app, free from HTTP 403 errors.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/16102739/dev-server-http-error-403-forbidden/28526284#28526284
Reply all
Reply to author
Forward
0 new messages