Я просмотрел официальную документацию Paho и попробовал упомянутые примеры. Я получаю ошибки при импорте Paho в качестве клиента. Ошибка выглядит следующим образом
File "/root/Desktop/aws_iot.py", line 1, in <module>
import paho.mqtt.client as mqtt
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 54, in <module>
from urllib import request as urllib_dot_request
File "/usr/lib/python3.7/urllib/request.py", line 88, in <module>
import http.client
File "/usr/lib/python3.7/http/client.py", line 71, in <module>
import email.parser
File "/usr/lib/python3.7/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/lib/python3.7/email/feedparser.py", line 27, in <module>
from email._policybase import compat32
File "/usr/lib/python3.7/email/_policybase.py", line 9, in <module>
from email.utils import _has_surrogates
File "/usr/lib/python3.7/email/utils.py", line 33, in <module>
from email._parseaddr import quote
File "/usr/lib/python3.7/email/_parseaddr.py", line 16, in <module>
import time, calendar
File "/root/Desktop/calendar.py", line 6, in <module>
from google_auth_oauthlib.flow import InstalledAppFlow
File "/usr/local/lib/python3.7/dist-packages/google_auth_oauthlib/__init__.py", line 21, in <module>
from .interactive import get_user_credentials
File "/usr/local/lib/python3.7/dist-packages/google_auth_oauthlib/interactive.py", line 24, in <module>
import google_auth_oauthlib.flow
File "/usr/local/lib/python3.7/dist-packages/google_auth_oauthlib/flow.py", line 64, in <module>
import wsgiref.simple_server
File "/usr/lib/python3.7/wsgiref/simple_server.py", line 13, in <module>
from http.server import BaseHTTPRequestHandler, HTTPServer
File "/usr/lib/python3.7/http/server.py", line 147, in <module>
class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
File "/usr/lib/python3.7/http/server.py", line 618, in BaseHTTPRequestHandler
MessageClass = http.client.HTTPMessage
AttributeError: module 'http' has no attribute 'client'
На данный момент я выполнял код, указанный в официальной документации.
Код
import paho.mqtt.client as mqtt
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
client.subscribe("$SYS/#")
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("mqtt.eclipse.org", 1883, 60)
# Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting.
# Other loop*() functions are available that give a threaded interface and a
# manual interface.
client.loop_forever()