0

I am working on Google Cloud IoT core and there I came across a problem in one of the samples (end-to-end example) provided in the online docs: google cloud iot exercise

There are two scripts, for Server and Device, and while running the device script I am facing this problem:

Antti29
  • 2,953
  • 12
  • 34
  • 36
Aadhar Bhatt
  • 641
  • 6
  • 6
  • the code of those scripts are:- https://github.com/aadharbhatt/pub-sub-work/blob/master/cloudiot_pubsub_example_mqtt_device.py https://github.com/aadharbhatt/pub-sub-work/blob/master/cloudiot_pubsub_example_server.py – Aadhar Bhatt Oct 10 '17 at 08:56
  • __Please add some details to your post itself and to the title.__ This is not a chat box but a problem solving library. Questions should be carefully edited so not only those that can provide a sollution, but also those that have a similar problem in a different context can find your question in the future. – Dirk Horsten Oct 10 '17 at 09:45

3 Answers3

1

From the commandline args, it looks like you're passing in rsa_cert.pem, which is your SSL private key. As @class said, you need to wget the Google root certificate (wget https://pki.google.com/roots.pem) and then pass the path to downloaded roots.pem for the --ca_certs argument.

Gabe Weiss
  • 3,134
  • 1
  • 12
  • 15
0

It's possible that your firewall (e.g. the Cloud Shell Machine) is blocking Python from connecting via port 8883. Can you try calling the cloudiot_pubsub_example_mqtt_device.py script with the port set to 443, e.g.

python <your_existing_parameters> --mqtt_bridge_port=443

You may also want to try using the HTTP device sample to publish messages as it also doesn't use port 8883, which may be blocked on your network.

In my tests, I was only able to run the exercise from the Google Cloud Shell after setting my port to 443, this hopefully will resolve the issue for you.

Note If you're encountering issues with verifying the server certificate, you need to download the Google root certificate by calling:

wget https://pki.google.com/roots.pem

Update You may also want to try to set the Python version in your virtual environment to Python 2 by setting up the virtual environment as:

virtualenv env --python=python2
class
  • 8,621
  • 29
  • 30
0

error image

Traceback (most recent call last):
  File "cloudiot_pubsub_example_mqtt_device.py", line 249, in <module>
    main()
  File "cloudiot_pubsub_example_mqtt_device.py", line 213, in main
    client.connect(args.mqtt_bridge_hostname, args.mqtt_bridge_port)
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 
768, in connect
    return self.reconnect()
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 
927, in reconnect
    sock.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 788, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 
(_ssl.c:581)
Aadhar Bhatt
  • 641
  • 6
  • 6