AWS IoT socket.gaierror: [Errno -3] Temporary failure in name resolution - aws-iot

My project needs to use MQTT client (AWS IoT) between Beaglebone and PC as middleware.
I used AWS IoT in my Flask framework in my pc's platform.
I use the same endpoint's MQTT client in my Beaglebone and my PC.
And I use AWSIOTPythonSDK to connect my MQTT client. The thing is when I connect with my BBB(I also use Flask framework), it works and has no latency. But when I connect with my PC (with I use Flask framework), in the beginning, it works. But when I wait about 10 minutes, it shows the bug and cannot connect successfully.
here is all the error message:
"/home/ran/MutantRobotics/src/rovers/Django/django_auth/django_auth/views.py", line 50, in <module>
myMQTTClient.connect()
File "/usr/local/lib/python3.5/dist-packages/AWSIoTPythonSDK/MQTTLib.py", line 481, in connect
return self._mqtt_core.connect(keepAliveIntervalSecond)
File "/usr/local/lib/python3.5/dist-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 183, in connect
self.connect_async(keep_alive_sec, self._create_blocking_ack_callback(event))
File "/usr/local/lib/python3.5/dist-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 196, in connect_async
rc = self._internal_async_client.connect(keep_alive_sec, ack_callback)
File "/usr/local/lib/python3.5/dist-packages/AWSIoTPythonSDK/core/protocol/internal/clients.py", line 116, in connect
rc = self._paho_client.connect(host, port, keep_alive_sec)
File "/usr/local/lib/python3.5/dist-packages/AWSIoTPythonSDK/core/protocol/paho/client.py", line 654, in connect
return self.reconnect()
File "/usr/local/lib/python3.5/dist-packages/AWSIoTPythonSDK/core/protocol/paho/client.py", line 776, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python3.5/socket.py", line 693, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.5/socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution
So does this means each endpoint just has one client???
I wanna have multiple clients in one endpoint MQTT client
Thanks

Related

GAE and urllib2.py errors with and without SSL and Sockets - TypeError: __init__() got an unexpected keyword argument 'context'

I have a service on GAE which retrieves data from different sources online. Each provider has a different authentication protocol and so far I've been able to connect to all of them with a mix of standard urllib2 calls or oauth mechanisms.
Recently one of them switched to the json-rpc with client certificates authentication. In order to make it work I had to enable billing on GAE, import the ssl module, force httplib to use sockets and patch some modules to make it work on the dev environment (see here)
I got that working in the end.
However, as soon as I force httplib to use sockets...
env_variables:
GAE_USE_SOCKETS_HTTPLIB : 'anyvalue'
...all the other scripts relying on very simple urllib2 calls like this one...
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
request = urllib2.Request(url)
response = opener.open(request)
...start to fail!!!
Here is the traceback:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
context=self._context)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1166, in do_open
h = http_class(host, timeout=req.timeout, **http_conn_args)
TypeError: __init__() got an unexpected keyword argument 'context'
I can't figure out why this is happening. I found some threads here on stackoverflow that mention a bug in Python 2.7.9 that should be fixed in 2.7.10 (which I'm using).
Anyone came across a similar issue?
Make sure you're using the latest version of the GAE SDK. Some previous versions were incompatible with python >=2.7.9 (see this issue for more information).

Why does using the Google APIs Python client in appengine with GAE_USE_SOCKETS_HTTPLIB result in ResponseNotReady

The code will work just fine in the SDK, but on Google AppEngine, it explodes:
File "./oauth2client/util.py", line 137, in positional_wrapper
File "./googleapiclient/discovery.py", line 197, in build
File "./oauth2client/util.py", line 137, in positional_wrapper
File "./oauth2client/client.py", line 563, in new_request
File "./httplib2/__init__.py", line 1608, in request
File "./httplib2/__init__.py", line 1350, in _request
File "./httplib2/__init__.py", line 1306, in _conn_request
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/python_std_lib/httplib.py", line 1033, in getresponse
raise ResponseNotReady()
ResponseNotReady
This only happens when GAE_USE_SOCKETS_HTTPLIB is on.
This happens because the Google API library is not aware of this and blindly uses a socket to connect to https://www.googleapis.com, which is not allowed. Further, the actual code hides the real error, which a permission denied on trying to create a socket.
I'm not aware of any workaround, except disabling sockets for httplib, or not using the provided libraries, but using a requests based one and installing an adapter that uses urlfetch for these domains.
Socket connections are only available for paid apps. Have you setup billing for your app?
From the documentation on sockets:
Sockets are only available for paid apps, and traffic from sockets is billed asĀ outgoing bandwidth.
Why are you trying to use sockets anyway?
In addition to #gcbirzan's answer. Below would be steps to make it work :-
Commenting GAE_USE_SOCKETS_HTTPLIB: True if it's set in app.yaml under env_variables
For requests installing requests_toolbelt using pip install -t lib/ requests_toolbelt(make sure you have requests version >= 2.10.0 for this to work)
Include below lines in main.py to enable requests_toolbelt adapter
import requests_toolbelt.adapters.appengine
requests_toolbelt.adapters.appengine.monkeypatch()
Above steps should be enough to solve this issue.

Google cloud storage - permission denied exception

I am trying to access cloud storage bucket ,of my appengine project from another appengine project .
Since the cloud storage bucket is present in another project , I provided permission as mentioned here.
Traceback (most recent call last):
File "/base/data/home/apps/s~dutch-barber/1.379022461794999395/barber/bems/service/__be_service_resource.py", line 182, in dispatch
uploadToGcs(featuredImage,file_url)
File "/base/data/home/apps/s~dutch-barber/1.379022461794999395/cloud_barber/utils.py", line 118, in uploadToGcs
writable_file_name = files.gs.create(filePath,mime_type=file.content_type,cache_control='no-cache')
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/files/gs.py", line 331, in create
return files._create(_GS_FILESYSTEM, filename=filename, params=params)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/files/file.py", line 650, in _create
_make_call('Create', request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/files/file.py", line 255, in _make_call
_raise_app_error(e)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/files/file.py", line 213, in _raise_app_error
raise PermissionDeniedError(e)
PermissionDeniedError: ApplicationError: 8
the link which you mentioned in your question has been deprecated.
Check the newer version of Google Cloud Storage Client Library and install it. Then, give it a try.
You could use the Developer Console to edit permission of your bucket. You will be able to add a project and set it as a owner / reader / writer

How can I solve 'Unable to find consistent port localhost' App Engine error?

I'm attempting to run Google App Engine just to get a hello world app up but have been failing. I'm on Windows 7 and have tried to use the GUI launcher as well as the Cygwin terminal. Having followed many different suggestions from SO forums (Failed to start devlopment server -- BindError: Unable to find a consistent port localhost) and others:
-I have edited the localhosts entry in the etc/hosts file to 127.0.0.1
-I've reinstalled the Google App Engine package
-Tried editing the .yaml and main.py files
-Tried changing the port to 9000 and 8888
-Tried explicitly specifying the host I'm launching on? (eg: --skip_sdk_update_check=yes --port=8080 --admin_port=8000 --host 127.0.0.1)
-Tried specifically allowing the app engine launcher to communicate through the firewall
Nothing has made a difference yet.
The error message reads:
"2013-07-13 16:35:05 Running command: "['C:\\Python27\\python.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=8080', '--admin_port=8000', u'C:\\Users\\Greg\\hello-udacity']"
INFO 2013-07-13 16:35:12,631 devappserver2.py:528] Skipping SDK update check.
WARNING 2013-07-13 16:35:12,655 api_server.py:314] Could not initialize images API; you are likely missing the Python "PIL" module.
WARNING 2013-07-13 16:35:12,660 simple_search_stub.py:955] Could not read search indexes from c:\users\greg\appdata\local\temp\appengine.hello-udacity\search_indexes
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 182, in <module>
_run_file(__file__, globals())
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 178, in _run_file
execfile(script_path, globals_)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 695, in <module>
main()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 688, in main
dev_server.start(options)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 659, in start
apis.start()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\api_server.py", line 137, in start
super(APIServer, self).start()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\wsgi_server.py", line 298, in start
raise BindError('Unable to find a consistent port %s' % host)
google.appengine.tools.devappserver2.wsgi_server.BindError: Unable to find a consistent port localhost
2013-07-13 16:35:12 (Process exited with code 1)"
From the error message it appears you are explicitly passing --skip_sdk_update_check=yes --port=8080 --admin_port=8000
Have you tried specifying the host you are launching on? eg:
--skip_sdk_update_check=yes --port=8080 --admin_port=8000 --host 127.0.0.1
Another item of interest would be to temporarily kill any firewalls you have running on your machine and see if that makes a difference.
Ran into this problem with a colleague in China with Astrall VPN running on the machine. Changed from Open mode to Stealth Mode, and this fixed the problem.
It's probably too late, but I just ran into this same condition after updating AppEngine SDK.
In the "wsgi_server.py" file edit the following line
class WsgiServer(object):
.....
def start(self):
try:
addrinfo = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
to
class WsgiServer(object):
.....
def start(self):
try:
addrinfo = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
socket.SOCK_STREAM, 1, socket.AI_PASSIVE)

Why is dev_appserver.py (App Engine dev server) hanging waiting for a request?

I've been seeing this error more and more lately. I'm using the Chrome dev-channel browser on Ubuntu 10.10. When I refresh a web page - the dev_appserver seems to hang. After a timeout, if completes the request.
If I type CTRL-C in the appserver terminal window, it seems to "unstick" the server after displaying this back trace:
Exception happened during processing of request from ('192.168.1.19', 48238)
Traceback (most recent call last):
File "/usr/local/lib/python2.5/SocketServer.py", line 222, in handle_request
self.process_request(request, client_address)
File "/usr/local/lib/python2.5/SocketServer.py", line 241, in process_request
self.finish_request(request, client_address)
File "/usr/local/lib/python2.5/SocketServer.py", line 254, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/google_appengine/google/appengine/tools/dev_appserver.py", line 3123, in __init__
BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
File "/usr/local/lib/python2.5/SocketServer.py", line 522, in __init__
self.handle()
File "/usr/local/lib/python2.5/BaseHTTPServer.py", line 316, in handle
self.handle_one_request()
File "/usr/local/lib/python2.5/BaseHTTPServer.py", line 299, in handle_one_request
self.raw_requestline = self.rfile.readline()
File "/usr/local/lib/python2.5/socket.py", line 346, in readline
data = self._sock.recv(self._rbufsize)
KeyboardInterrupt
Oddly, when I brought up Firefox to see if it's related to Chrome-only, the problem went away (both on Firefox AND on Chrome).
I'm interpreting this as the browser keeping the previous request open by not completely pulling all the bytes from the response. Since the dev_server is single-threaded,
it will not process any further requests until the old one times out.
Anyone have any other insight here? It's extremely annoying when this happens, as I have to kill and restart the app_devserver to keep going.
There are several posts about this in the groups. Apparently Chrome will sends multiple requests, then it somehow winds up that the SDK blocks on one of the requests.
I've seen a few users say starting Chrome with --disable-preconnect helps.

Resources