跳至內容
選單
此問題已被標幟
1 回覆
1336 瀏覽次數

We have a dedicated Odoo.sh server.

It is configured to allow direct SQL access:

odoosh-sql-access init

 
We have been able to successfully connect but can't run any SQL, even a simple SELECT:

import psycopg2

connection = psycopg2.connect(database="db",
user="user",
password="password",
host="host",
port="5432",
sslmode="require")

cursor = connection.cursor() # ✅ this works ✅

cursor.execute("SELECT * FROM res_partner;") # ❌ this FAILS ❌

connection.close()



頭像
捨棄
最佳答案

Transactions are not supported with the direct access method.

You need to modify your psycopg2.connect call to add:

autocommit=True

Without this option, psycopg2 will implicitly start a transaction when calling execute which is not allowed by the server. 

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
4月 22
3807
1
3月 22
3171
5
3月 20
17915
2
5月 17
10268
2
3月 15
7588