Moved Permanently error when running dev_appserver.py - python

I am trying the basic helloworld example (https://developers.google.com/appengine/docs/python/gettingstartedpython27/helloworld) and keep getting the HTTP Error 301: Moved Permanently error whenever I try to test my code using dev_appserver.py
The 2 files I have are copied and pasted exactly from the developers.google.com site.
I have included the location of where dev_appserver.py is in both PATH and PYTHONPATH
I am running this on Linux with python 2.7.3 and appengine v1.8.4
The output on the terminal when I run this is...
[verma#localhost python]$ dev_appserver.py helloworld/
WARNING 2013-09-11 04:45:49,988 api_server.py:327] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO 2013-09-11 04:45:49,999 api_server.py:138] Starting API server at: http://localhost:57128
INFO 2013-09-11 04:45:50,021 dispatcher.py:164] Starting module "default" running at: http://localhost:8080
INFO 2013-09-11 04:45:50,023 admin_server.py:117] Starting admin server at: http://localhost:8000
HTTPError()
HTTPError()
Traceback (most recent call last):
File "/home/verma/Documents/gae/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 1302, in communicate
req.respond()
File "/home/verma/Documents/gae/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 831, in respond
self.server.gateway(self).respond()
File "/home/verma/Documents/gae/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 2115, in respond
response = self.req.server.wsgi_app(self.env, self.start_response)
File "/home/verma/Documents/gae/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 256, in __call__
return app(environ, start_response)
File "/home/verma/Documents/gae/google_appengine/google/appengine/tools/devappserver2/request_rewriter.py", line 311, in _rewriter_middleware
response_body = iter(application(environ, wrapped_start_response))
File "/home/verma/Documents/gae/google_appengine/google/appengine/tools/devappserver2/python/request_handler.py", line 97, in __call__
self._flush_logs(response.get('logs', []))
File "/home/verma/Documents/gae/google_appengine/google/appengine/tools/devappserver2/python/request_handler.py", line 233, in _flush_logs
apiproxy_stub_map.MakeSyncCall('logservice', 'Flush', request, response)
File "/home/verma/Documents/gae/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 94, in MakeSyncCall
return stubmap.MakeSyncCall(service, call, request, response)
File "/home/verma/Documents/gae/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 328, in MakeSyncCall
rpc.CheckSuccess()
File "/home/verma/Documents/gae/google_appengine/google/appengine/api/apiproxy_rpc.py", line 156, in _WaitImpl
self.request, self.response)
File "/home/verma/Documents/gae/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 200, in MakeSyncCall
self._MakeRealSyncCall(service, call, request, response)
File "/home/verma/Documents/gae/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 226, in _MakeRealSyncCall
encoded_response = self._server.Send(self._path, encoded_request)
File "/home/verma/Documents/gae/google_appengine/google/appengine/tools/appengine_rpc.py", line 393, in Send
f = self.opener.open(req)
File "/usr/lib64/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/usr/lib64/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib64/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/usr/lib64/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib64/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 301: Moved Permanently
Traceback (most recent call last):
File "/home/verma/Documents/gae/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 1302, in communicate
req.respond()
File "/home/verma/Documents/gae/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 831, in respond
self.server.gateway(self).respond()
File "/home/verma/Documents/gae/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 2115, in respond
response = self.req.server.wsgi_app(self.env, self.start_response)
File "/home/verma/Documents/gae/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 256, in __call__
return app(environ, start_response)
File "/home/verma/Documents/gae/google_appengine/google/appengine/tools/devappserver2/request_rewriter.py", line 311, in _rewriter_middleware
response_body = iter(application(environ, wrapped_start_response))
File "/home/verma/Documents/gae/google_appengine/google/appengine/tools/devappserver2/python/request_handler.py", line 97, in __call__
self._flush_logs(response.get('logs', []))
File "/home/verma/Documents/gae/google_appengine/google/appengine/tools/devappserver2/python/request_handler.py", line 233, in _flush_logs
apiproxy_stub_map.MakeSyncCall('logservice', 'Flush', request, response)
File "/home/verma/Documents/gae/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 94, in MakeSyncCall
return stubmap.MakeSyncCall(service, call, request, response)
File "/home/verma/Documents/gae/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 328, in MakeSyncCall
rpc.CheckSuccess()
File "/home/verma/Documents/gae/google_appengine/google/appengine/api/apiproxy_rpc.py", line 156, in _WaitImpl
self.request, self.response)
File "/home/verma/Documents/gae/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 200, in MakeSyncCall
self._MakeRealSyncCall(service, call, request, response)
File "/home/verma/Documents/gae/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 226, in _MakeRealSyncCall
encoded_response = self._server.Send(self._path, encoded_request)
File "/home/verma/Documents/gae/google_appengine/google/appengine/tools/appengine_rpc.py", line 393, in Send
f = self.opener.open(req)
File "/usr/lib64/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/usr/lib64/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib64/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/usr/lib64/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib64/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 301: Moved Permanently
INFO 2013-09-11 04:46:01,635 module.py:593] default: "GET / HTTP/1.1" 500 -
I have a feeling I am missing something very basic but can't find it. By the way this was working a few days back and I don't remember doing anything stupid to break this :-(

Quick Solution to Fix your Problem.
Open FILE [GAE Installation path]/google/appengine/tools/appengine_rpc.py"
Goto Line 578
Comment out the following line
# opener.add_handler(fancy_urllib.FancyProxyHandler())

It appears that dev_apserver needs to contact the google app engine servers on the internet every once in a while (even if you do not ask it to check for updates). The problem I had was that it cannot access the google servers when behind a proxy (even though I have properly exported http_proxy and https_proxy).
When I use a wired network directly connected to the internet I have no problems at all.
Once dev_appserver has 'called home', it will continue to work without issue behind a proxy for a few more days, and then I get this problem again.
In the past I have noticed similar behavior when connected on wifi as well.
It appears that dev_appserver works best when on a wired network without proxies.
This is based simply on my observations; it would be great if someone could give a definitive answer to this question.

Related

python jenkins api quiet_down() not working

I am trying to send quiet_down() using python-jenkins api but I get the following messages and the server doesn't go into shutdown mode.
import jenkins
server = jenkins.Jenkins('serveraddress', username='someuser', password='somepassword')
server.quiet_down()
Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\site-packages\jenkins__init__.py", line 1642, in quiet_
down
self.jenkins_open(request)
File "C:\Python27\lib\site-packages\jenkins__init__.py", line 431, in jenkins
_open
response = urlopen(req, timeout=self.timeout).read()
File "C:\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 435, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 548, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 473, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 407, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 556, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 405: Method Not Allowed
I have checked and I'm being authenticated correctly and I do have all the rights on it. Jenkins version is 2.7.4.
Any help would be appreciated.
Thanks.

Jenkins Python API, create_node(), error: 400

I'm setting my jenkins environment and, as part of this process, I need to create a slave node.
Bellow follow the script that is crashing:
import jenkins
server = jenkins.Jenkins('http://localhost:9090')
server.create_node('slave')
Follows the output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/jenkins/__init__.py", line 1156, in create_node
self._build_url(CREATE_NODE, params), b''))
File "/usr/local/lib/python2.7/dist-packages/jenkins/__init__.py", line 341, in jenkins_open
response = urlopen(req, timeout=self.timeout).read()
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
Use jenkinsapi module,
from jenkinsapi.jenkins import Jenkins
server = Jenkins('http://localhost:9090')
server.create_node('slave')
It appears to be a bug in python-jenkins 0.4.11, which was fixed by commit
302eb5dad6439842e076fead5bd76f20f615e6a8.
I got a similar error, upgrading python-jenkins fixed it.

Nagios - Hipchat integration through Hipsaint

We are trying to integrate nagios (4.1.1) notifications with Hipchat using Hipsaint. We followed the instructions posted here (keep in mind that the instructions mention nagios 3). We filled in the Token and Room_ID. We get the following output:
:~# hipsaint --token=XXXXXXXXXX --room=XXXXXXX --type=host --inputs="$HOSTNAME$|$LONGDATETIME$|$NOTIFICATIONTYPE$|$HOSTADDRESS$|$HOSTSTATE$|$HOSTOUTPUT$" -n
Traceback (most recent call last):
File "/usr/local/bin/hipsaint", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/hipsaint/bin/commands.py", line 78, in main
msg.deliver_payload()
File "/usr/local/lib/python2.7/dist-packages/hipsaint/messages.py", line 68, in deliver_payload_v1
raw_response = urlopen(self.urlv1, message_params)
File "/usr/lib/python2.7/urllib2.py", line 133, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 416, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 529, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 454, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 388, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 537, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized
We also tried the following:
Using a new Token
Updating Python from ver 2.7 to 3
Opening the ports for hipchat on the nagios Security Group
Any idea how we can proceed?
Test the validity of your auth token and make sure the test is not responding with "401 Unauthorized" status.
If you're using your own private HipChat Server, replace api.hipchat.com with your HipChat Server hostname.
Replace YOUR_TOKEN with the auth token you generated. Execute the following from your Nagios server:
curl https://api.hipchat.com/v1/rooms/list?auth_token=YOUR_TOKEN&auth_test=true
Source: https://www.hipchat.com/docs/api/auth

HTTP Error 401: Authorization Required intermittent

This is more of a linux/security related question (than Python's urllib2 authentication question)
My setup is:
I am running a Ubuntu Server in my company's corporate network
I notice that when I try to access the internet via a browser (chrome or firefox), I intermittently get redirected to company's security page asking me for my company's credentials.
Ubuntu server's firewall is disabled.
I am not sure why, but when I try running the following script (to fetch data from internet, even google.com), this script intermittently fails due to 401 Authorization Required Error. Once this happens, then I have to open a browser (obviously access via VNC) and then go to any page and I have to enter my credentials. And once I do, then the script runs just fine for a while. And after a while, it fails due 401 error again.
Script
import urllib2
url = 'http://nominatim.openstreetmap.org/search.php?countrycodes=us&state=colorado&street=6900+W+25th+Ave&format=json&addressdetails=1&polygon_geojson=1'
request = urllib2.Request(url)
response = urllib2.urlopen(request).read()
print response
Traceback (most recent call last):
File "/home/amit/workspace/clink/device_polling/mydb/dbmanager.py", line 1554, in _poll_device
self.update__device_geoloc(deviced_alldb, mydbc, hpnac, logobj)
File "/home/amit/workspace/clink/device_polling/mydb/dbmanager.py", line 1387, in update__device_geoloc
geoinfo = get_coordinates_geolocation(state=state, city=city, street=street, countrycodes=countrycodes)
File "/home/amit/workspace/clink/device_polling/utils/utils.py", line 386, in get_coordinates_geolocation
response = urllib2.urlopen(req)
File "/miniconda/envs/py_env_clink/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/miniconda/envs/py_env_clink/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/miniconda/envs/py_env_clink/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/miniconda/envs/py_env_clink/lib/python2.7/urllib2.py", line 442, in error
result = self._call_chain(*args)
File "/miniconda/envs/py_env_clink/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/miniconda/envs/py_env_clink/lib/python2.7/urllib2.py", line 629, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/miniconda/envs/py_env_clink/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/miniconda/envs/py_env_clink/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/miniconda/envs/py_env_clink/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/miniconda/envs/py_env_clink/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/miniconda/envs/py_env_clink/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 401: Authorization Required
I don't understand why this is happening? Does any security guy know what I should look here for? I am sure it has to do with my corporate firewall which periodically requests my ubuntu server for password

Urllib2 - Django - Broken Pipe

I am new to Django and I am experiencing some troubles posting data to a django webapp.
On the django side I have a form (backed by couchdb - couchdbkit django ext.).
On the client side I post data with urllib2, in bulk (going through a list of data to post one by one)
data = urllib.urlencode(param)
req = urllib2.Request(OBJECT_SERVICE_URL + '/objects/create/', data)
req.add_header('Content-type', 'application/x-www-form-urlencoded')
res = urllib2.urlopen(req)
res.close()
After one record (one post passing), it get the message below, running again the next line passes and I have again this message :
res = urllib2.urlopen(req)
File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.6/urllib2.py", line 397, in open
response = meth(req, response)
File "/usr/lib/python2.6/urllib2.py", line 510, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.6/urllib2.py", line 435, in error
return self._call_chain(*args)
File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib/python2.6/urllib2.py", line 518, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: INTERNAL SERVER ERROR
The server says :
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 284, in run
self.finish_response()
File "/usr/local/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 324, in finish_response
self.write(data)
File "/usr/local/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 420, in write
self._write(data)
File "/usr/lib/python2.6/socket.py", line 318, in write
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 59571)
self.flush()
File "/usr/lib/python2.6/socket.py", line 297, in flush
self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 104] Connection reset by peer
Traceback (most recent call last):
File "/usr/lib/python2.6/SocketServer.py", line 283, in _handle_request_noblock
----------------------------------------
self.process_request(request, client_address)
File "/usr/lib/python2.6/SocketServer.py", line 309, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.6/SocketServer.py", line 322, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 570, in __init__
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
File "/usr/lib/python2.6/SocketServer.py", line 618, in __init__
self.finish()
File "/usr/lib/python2.6/SocketServer.py", line 661, in finish
self.wfile.flush()
File "/usr/lib/python2.6/socket.py", line 297, in flush
self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 32] Broken pipe
I must state that I am working on the embedded django development web server...
And here is the output of the test :
======================================================================
ERROR: test_create_object (objects.tests.ObjectAppTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/patrick/workspace_py/objects/tests.py", line 21, in test_create_object
rs = c.post('/objects/create/', param)
File "/usr/local/lib/python2.6/dist-packages/django/test/client.py", line 455, in post
response = super(Client, self).post(path, data=data, content_type=content_type, **extra)
File "/usr/local/lib/python2.6/dist-packages/django/test/client.py", line 256, in post
return self.request(**r)
File "/usr/local/lib/python2.6/dist-packages/django/test/client.py", line 387, in request
response = self.handler(environ)
File "/usr/local/lib/python2.6/dist-packages/django/test/client.py", line 84, in __call__
response = self.get_response(request)
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 169, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 218, in handle_uncaught_exception
return callback(request, **param_dict)
File "/home/patrick/workspace_py/env/lib/python2.6/site-packages/coffin/views/defaults.py", line 34, in server_error
content = render_to_string(template_name, Context({}))
File "/home/patrick/workspace_py/env/lib/python2.6/site-packages/coffin/template/loader.py", line 50, in render_to_string
template = get_template(template_name)
File "/home/patrick/workspace_py/env/lib/python2.6/site-packages/coffin/template/loader.py", line 24, in get_template
return env.get_template(template_name)
File "/home/patrick/workspace_py/env/lib/python2.6/site-packages/jinja2/environment.py", line 719, in get_template
return self._load_template(name, self.make_globals(globals))
File "/home/patrick/workspace_py/env/lib/python2.6/site-packages/jinja2/environment.py", line 693, in _load_template
template = self.loader.load(self, name, globals)
File "/home/patrick/workspace_py/env/lib/python2.6/site-packages/jinja2/loaders.py", line 115, in load
source, filename, uptodate = self.get_source(environment, name)
File "/home/patrick/workspace_py/env/lib/python2.6/site-packages/jinja2/loaders.py", line 377, in get_source
raise TemplateNotFound(template)
TemplateNotFound: 500.html
----------------------------------------------------------------------
Does anyone know how to fix ?
Patrick
Some times I found weird errors and quick connection resets using development server (like in your log). If your application is about http, REST and webservices you should use Apache or Gunicorn so you feel a more realistic enviroment while developing.

Categories