如何让[错误111]连接时使用Python代理服务器拒绝
问题描述:
我尝试测试在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