Vagrant python [Errno -2] Name or service not known - python

I am currently having a problem with vagrant. I used it before for a number of tasks, but now when I do vagrant up and then vagrant ssh, everything seems to work ok. Then I navigate into the vagrant folder to run a python file and when I run it I get the following error:
vagrant#vagrant:/vagrant$ python project.py
Traceback (most recent call last):
File "project.py", line 75, in
app.run(host='0.0.0.0.', port=8080)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 841, in run
run_simple(host, port, self, **options)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 720,
in run_simple
s.bind((hostname, port))
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.gaierror: [Errno -2] Name or service not known
I tried multiple times to restart vagrant, I also tried vagrant destroy and restarted the process. I manually deleted and powered it off a couple of times, but I always experience the same error. I would appreciate any help. Thank you.

The problem isn't vagrant... This line in the stacktrace shows there could be a typo in your python script
app.run(host='0.0.0.0.', port=8080)
Should be
app.run(host='0.0.0.0', port=8080)

Related

Cannot get python module ezsheets to work

I followed the steps from the official documentation for ezsheets. Both apis were activated (sheets and drive) and I turned on a python shell and imported the ezsheets module. But, it did not open the new browser window like the documentation said it's supposed to. I then tried and successfully got google sheets working with googles' quickstart script. I have the credentials-sheets.json and token.pickle in the same folder as my python scripts. Sheets api seems to work just fine on it's own but when I try it with ezsheets module I get a following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/method/.local/share/virtualenvs/python_projects-sgt8dc05/lib/python3.6/site-packages/ezsheets/__init__.py", line 1559, in listSpreadsheets
if not IS_INITIALIZED: init()
File "/home/method/.local/share/virtualenvs/python_projects-sgt8dc05/lib/python3.6/site-packages/ezsheets/__init__.py", line 1520, in init
creds = flow.run_local_server()
File "/home/method/.local/share/virtualenvs/python_projects-sgt8dc05/lib/python3.6/site-packages/google_auth_oauthlib/flow.py", line 443, in run_local_server
host, port, wsgi_app, handler_class=_WSGIRequestHandler)
File "/usr/lib/python3.6/wsgiref/simple_server.py", line 153, in make_server
server = server_class((host, port), handler_class)
File "/usr/lib/python3.6/socketserver.py", line 456, in __init__
self.server_bind()
File "/usr/lib/python3.6/wsgiref/simple_server.py", line 50, in server_bind
HTTPServer.server_bind(self)
File "/usr/lib/python3.6/http/server.py", line 136, in server_bind
socketserver.TCPServer.server_bind(self)
File "/usr/lib/python3.6/socketserver.py", line 470, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use
ezsheets is trying to open webserver on port 8000 to obtain access token. But it is already occupied by another app.
Chech what app listens on port 8000 and close it.
On Linux you can check it with
netstat -tulpn | grep 8000
On Windows:
netstat -ab

Bottle python program runs in dev environment but not in live environment

I am trying to get python bottle application running, but for some reason it fails. I am using bottle 0.13 and python 2.7 on cent os 7.2 version.
The same program runs in dev environment which has centos 6.7 but not in live environment. I get the following stack trace:
File "helloworld.py", line 7, in <module>run(host='localhost', port=8080)
File "/bottle.py", line 3127, in run server.run(app) File "/bottle.py", line 2781, in run
srv = make_server(self.host, self.port, app, server_cls, handler_cls)
File "/usr/lib64/python2.7/wsgiref/simple_server.py", line 144, in make_server
server = server_class((host, port), handler_class)
File "/usr/lib64/python2.7/SocketServer.py", line 420, in _init_self.server_activate()
File "/usr/lib64/python2.7/SocketServer.py", line 439, in server_activate
self.socket.listen(self.request_queue_size)
File "/usr/lib64/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)socket.error: [Errno 98] Address already in use
Any help will be appreciated.
Looks like there is already a process listening on port 8080. You can use the follow command to check who is using 8080:
lsof -i :8080
To change the port, edit port=8080 parameter to some other port and rerun application:
run(host='localhost', port=8080)

Connection to AWS timed out using Python boto

I ran Python program in Cygwin to connect to AWS, but failed consistently as being timed out. But my connection to AWS using aws cli in Cygwin always works. Also if I run the same python code in Windows, it also works. I have checked all the connection credentials which are the same for all.
Here is the error msg:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/ec2/connection.py", line 585, in get_all_instances
max_results=max_results)
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/ec2/connection.py", line 681, in get_all_reservations
[('item', Reservation)], verb='POST')
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1170, in get_list
response = self.make_request(action, params, path, verb)
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1116, in make_request
return self._mexe(http_request)
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1030, in _mexe
raise ex
socket.error: [Errno 116] Connection timed out
I have found out that the culprit lies in the proxy credentials.
I put HTTP_PROXY and HTTPS_PROXY as Windows Environment Variables. However, when run in Cygwin, boto uses 'http_proxy' to match without considering the case of the word
(see /boto/connection.py(669)handle_proxy()
line 669: if 'http_proxy' in os.environ and not self.proxy:).
When I changed the capital case HTTP_PROXY to lower case http_proxy, then it worked. Not sure why it isn't a problem if I run with Python in Windows.

redis.exceptions.ConnectionError: Error -2 connecting to localhost:6379. Name or service not known

I have this error when I run my code in server, my env is debian, and Python2.7.3
Traceback (most recent call last):
File "fetcher.py", line 4, in <module>
import mirad.fetcher_tasks as tasks
File "/home/mirad/backend/mirad/fetcher_tasks.py", line 75, in <module>
redis_keys = r.keys('*')
File "/home/mirad/backend/venv/local/lib/python2.7/site-packages/redis/client.py", line 863, in keys
return self.execute_command('KEYS', pattern)
File "/home/mirad/backend/venv/local/lib/python2.7/site-packages/redis/client.py", line 534, in execute_command
connection.send_command(*args)
File "/home/mirad/backend/venv/local/lib/python2.7/site-packages/redis/connection.py", line 532, in send_command
self.send_packed_command(self.pack_command(*args))
File "/home/mirad/backend/venv/local/lib/python2.7/site-packages/redis/connection.py", line 508, in send_packed_command
self.connect()
File "/home/mirad/backend/venv/local/lib/python2.7/site-packages/redis/connection.py", line 412, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error -2 connecting to localhost:6379. Name or service not known.
when I run redis-cli it works correctly without any error:
$ redis-cli
127.0.0.1:6379>
It seems that you are trying connect redis with server that is unidentified by your current Debian environment.
From Traceback, I see you are trying to connect using host name as localhost ,
r_server=redis.Redis(host="localhost",port=6379)
But , your system is unable to understand "localhost" , make entry in hosts file i.e saying 127.0.0.1 is localhost. add below code in /etc/hosts
127.0.0.1 localhost
otherwise connect redis using below command ;
r_server=redis.Redis(host="127.0.0.1",port=6379)
I faced a similar problem and later on realized that I have not opened redis in the terminal by command: $ redis-server.
Maybe it is the case.

Configuring the Google App Engine SDK for offline use

How can I configure the Google App Engine SDK to run the local development server without requiring a network connection? I've tried removing ~/.appcfg_nag and setting --skip_sdk_update_check at runtime, but it still fails with the following error:
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
EDIT: Here's the complete command and error output:
$ dev_appserver.py helloworld/
INFO 2012-02-20 20:00:19,712 py_zipimport.py:148] zipimporter('/Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-fat.egg', 'MySQLdb/')
WARNING 2012-02-20 20:00:19,784 rdbms_mysqldb.py:94] The rdbms API is not available because the MySQLdb library could not be loaded.
Warning: You are using a Python runtime (2.6) that is more recent than the production runtime environment (2.5). Your application may use features that are not available in the production environment and may not work correctly when deployed to production.
INFO 2012-02-20 20:00:19,859 appengine_rpc.py:159] Server: appengine.google.com
WARNING 2012-02-20 20:00:19,874 dev_appserver.py:3396] Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
Traceback (most recent call last):
File "/usr/local/bin/dev_appserver.py", line 99, in <module>
run_file(__file__, globals())
File "/usr/local/bin/dev_appserver.py", line 95, in run_file
execfile(script_path, globals_)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_main.py", line 692, in <module>
sys.exit(main(sys.argv))
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_main.py", line 656, in main
persist_logs=persist_logs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 3594, in CreateServer
server = HTTPServerWithScheduler((serve_address, port), handler_class)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 3622, in __init__
request_handler_class)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py", line 400, in __init__
self.server_bind()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py", line 411, in server_bind
self.socket.bind(self.server_address)
File "<string>", line 1, in bind
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
The default behavior is to bind to 127.0.0.1, which is resolved to "localhost" by looking it up on /etc/hosts (or vice-versa). Try forcing it to bind to 127.0.0.1:8080 by starting it as "dev_appserver.py helloworld -a 127.0.0.1 -p 8080" or bind it to all local addresses with "dev_appserver.py helloworld -a 0.0.0.0 -p 8080" and see what happens.

Categories

Resources