1
我嘗試測試在Python Odoo Web Service API,一切工作正常從本地主機使用基本的Django應用程序和的xmlrpclib。但是,當我在host it我pythonanywhere得到[錯誤111]拒絕連接錯誤:如何讓[錯誤111]連接時使用Python代理服務器拒絕
在他們的幫助頁面they describe該端口在proxy.server的免費賬戶,他們的HTTP代理關閉:3128必須使用。怎麼做?
其實應該沒有代理工作,一旦添加.odoo.com他們whitelist,但代理的問題很有趣,我也知道如何在不同的主機上運行這個程序。
這是我的觀點的Django的代碼(是的,我知道這是不好的做法,把HTML視圖,只是爲了測試):
from django.http import HttpResponse
import xmlrpclib
url = "https://demo3.odoo.com"
db = "demo_100_1489044950"
username = "admin"
password = "admin"
#odoo service connection
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
products = models.execute_kw(db, uid, password,
'product.template', 'search_read',
[[]],
{'fields': ['name', 'list_price'], 'limit': 10})
for product in products:
print product['id'], product['name'], product['list_price']
def index(request):
html = "<html><body><h1>Odoo Products</h1>"
for product in products:
name = product['name'].encode("utf-8", "strict")
html += "<div>"+name+": "+str(product['list_price'])+"</div>"
html += "</body></html>"
return HttpResponse(html)
PS:Django應用程序的源代碼是this github repository
感謝您的鏈接,即工作。我希望我可以在你的答案中添加一個代碼示例。 – geraldo
這是確定的,據我擔心,但它看起來像主持人寧願代碼示例是註釋的一部分,而不是一個編輯。 –
沒有問題,代碼是在github上回購所以應該很容易找到感興趣的脂肪酶。 – geraldo