ca_certs: FileNotFoundError: [Errno 2] No such file or directory
Get stuck with that error for a little bit.
$ python --version
Python 3.7.0
$ uname -a
Darwin 16.0.0 Darwin Kernel Version 16.0.0: Mon Aug 29 17:56:20 PDT 2016; root:xnu-3789.1.32~3/RELEASE_X86_64 x86_64
$ pipenv --version
pipenv, version 2018.7.1
Traceback:
Traceback (most recent call last):
File "send_messages.py", line 286, in <module>
main()
File "send_messages.py", line 237, in main
args.mqtt_bridge_hostname, args.mqtt_bridge_port)
File "send_messages.py", line 142, in get_client
client.tls_set(ca_certs=ca_certs, tls_version=ssl.PROTOCOL_TLSv1_2)
File "/Users/home/.local/share/virtualenvs/iot-core-zt_-zuGz/lib/python3.7/site-packages/paho/mqtt/client.py", line 703, in tls_set
context.load_verify_locations(ca_certs)
FileNotFoundError: [Errno 2] No such file or directory
Found this solution:
$ pipenv install certifi
$ cp /Users/home/.local/share/virtualenvs/iot-core-zt_-zuGz/lib/python3.7/site-packages/certifi/cacert.pem roots.pem
Not sure if that correct fix, but I did not find a much info in google so just want to post it here
It seems you are calling tls_set with ca_certs pointing to non existing file. With you fix, I assume ca_certs value is "root.pem", but as expected if that file does not exists, tls_set can't work. I don't understand what exactly is your issue, could you explain a bit more ?
@PierreF Nothing unusual
I tried to run google iot python example https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/iot/api-client/mqtt_example/cloudiot_mqtt_example.py
and got an error (i sent it above). First I thought that I'm missing some libraries on my machine but after few hours of debugging i found this workaround
Ok, got it. It's the GoogleCloudPlatform that require roots.pem to be present and does not seems to document it clearly enough.
For anyone looking for an answer to this - even though the sample parameter is optional, defaulting to roots.pem in the current path, you still will need to retrieve the root certificate from Google e.g. wget https://pki.goog/roots.pem.