小编Elv*_*rov的帖子

如何在python中调整base64编码图像的大小

我想在 python 中调整base64 编码图像的大小。我搜索但找不到。我用Pillow包来做的。然而Pillow却没有这样的功能。

python image-resizing python-imaging-library python-2.7 python-3.x

5
推荐指数
1
解决办法
5788
查看次数

psycopg2.ProgrammingError:无法适应类型“dict”

我在python中有一个sql类,它将数据插入到我的 PostgreSQL DB 中。在我的表中,一列是jsonfield,当我将数据插入该表时,我收到错误(psycopg2.ProgrammingError: can't adjustment type 'dict') 。

我使用过json.load 、 json.loads 、 json.dump 、 json.dumps。他们都没有工作。即使我尝试过字符串格式化。它也不起作用。

知道该怎么做吗?

我的代码如下

json_data = {
 "key": "value"
 }
query = """INSERT INTO  table(json_field) VALUES(%s)"""
self.cursor.execute(query, ([json_data,]))
self.connection.commit()

Run Code Online (Sandbox Code Playgroud)

python sql postgresql json python-3.x

5
推荐指数
1
解决办法
1万
查看次数

MQTT 订阅在多线程中无法正常工作

我有如下代码


    threads = []
    t = threading.Thread(target=Subscribe('username', "password", "topic", "host",port).start)
    t1 = threading.Thread(target=Subscribe('username2', "password2", "topic2", "host",port).start)
    
    threads.append(t)
    threads.append(t1)
    
    for thread in threads:
        thread.start()
    
    for thread in threads:
        thread.join()
Run Code Online (Sandbox Code Playgroud)

我的主题每 5 分钟发送一次数据

当我使用上面的代码时,它无法正常工作,有时发送数据有时不发送数据。

但是,当我使用一个没有线程的主题时,它工作正常,并且数据每 5 分钟完美地传入一次。

我怎么解决这个问题?我想同时订阅两个主题。

我正在使用Paho进行MQTT

我的订阅类别是

class Subscribe:

    def __init__(self, username, passowrd, topic, host, port):

        self.username = username
        self.password = passowrd
        self.topic = topic
        self.host = host
        self.port = port
       
      

    def start(self):
        self.mqttc = mqtt.Client(client_id="Python")
        self.connected = False
        self.mqtt_message = …
Run Code Online (Sandbox Code Playgroud)

python multithreading python-multithreading python-3.x mqtt

5
推荐指数
1
解决办法
542
查看次数