Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

API create_connection error (Name or service not known) to Odoo online server

api
By
Fausto R.
on 11/28/14, 9:43 AM 1,707 views

Hello
I am following the suggestions from this post (https://www.odoo.com/forum/help-1/question/is-the-xml-rpc-api-available-on-openerp-online-915) and using the sample code from openerplib, as follow

import openerplib

DATABASE = 'mydb'
USERNAME = 'admin'
PASSWORD = 'mypass'
SERVER = 'https://' + DATABASE + '.my.openerp.com'

connection = openerplib.get_connection(hostname=SERVER, \
    database=DATABASE, login=USERNAME, password=PASSWORD)
user_model = connection.get_model("res.user")
print user_model
ids = user_model.search([("login", "=", "admin")])
user_info = user_model.read(ids[0], ["name"])
print user_info["name"]
# will print "Administrator"

But getting a connection error as detailed below

<openerplib.main.Model object at 0xb70376cc>
Traceback (most recent call last):
  File "odoo-t2.py", line 12, in <module>
    ids = user_model.search([("login", "=", "admin")])
  File "build/bdist.linux-i686/egg/openerplib/main.py", line 305, in proxy
  File "build/bdist.linux-i686/egg/openerplib/main.py", line 243, in check_login
  File "build/bdist.linux-i686/egg/openerplib/main.py", line 180, in proxy
  File "build/bdist.linux-i686/egg/openerplib/main.py", line 83, in send
  File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1578, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1292, in single_request
    self.send_content(h, request_body)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1439, in send_content
    connection.endheaders(request_body)
  File "/usr/lib/python2.7/httplib.py", line 997, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 850, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 812, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 793, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python2.7/socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known

 

I have tried also with xmlrpclib and oerplib, with similar error results

This is the sample code using plain xmlrpclib (this is the one I'd like to see working !!!)

server = ServerProxy(SERVER + '/xmlrpc/common')
user_id = server.login(DATABASE, USERNAME, PASSWORD)

server = ServerProxy(SERVER + '/xmlrpc/object')
user_ids = server.execute(DATABASE, user_id, PASSWORD,
    'res.users', 'search', []
)

users = server.execute(DATABASE, user_id, PASSWORD,
    'res.users', 'read', user_ids, []
)

for user in users:
    print(user['id'], user['name'])

 

 

I should be missing something very trivial or connectiong to Odoo online requires something else?

Thanks for your support on my first steps into Odoo API land,

Fausto

 

0
Anabela Damas
On 11/28/14, 10:00 AM

Hi, 

A python to create users in my Openerp : 

# encoding: utf-8

from base64 import b64decode
import time
import xml.etree.ElementTree as ET
import datetime
from random import randint
from pprint import pprint
from xml.dom.minidom import parse, parseString
import xmlrpclib
import sys


class OpenERPClient:
    def __init__(self, host, port, username, password, dbname):
        self._host = host
        self._port = port
        self._username = username
        self._password = password
        self._dbname = dbname
        self._uid = None
        self._sock = None

    def login(self):
        sock_common = xmlrpclib.ServerProxy(
            "http://%s:%s/xmlrpc/common" % (self._host, self._port)
        )

        self._uid = sock_common.login(
            self._dbname, 
            self._username, 
            self._password)

        self._sock = xmlrpclib.ServerProxy(
            "http://%s:%s/xmlrpc/object" % (self._host, self._port)
        )

    def _exec_module_method(self, module, method, *args):
        return self._sock.execute(
            self._dbname, self._uid, self._password, 
            module, method, *args)


class TestClient(OpenERPClient):
    
    def create_user(self, data_dict):
        return self._exec_module_method(
            'res.users', 
            'create', 
            data_dict)

 

if __name__ == "__main__":

#(host, port, username, password, dbname)
    testobj = TestClient("192.168.250.110", "8069", "admin", "123qwe", "database")
    testobj.login()
    testobj.create_user({'name':'John','active': True,
                            'login': 'john',
                            'password': 'qwerty',
                            'tz': 'Europe/Lisbon', })

thanks, when using your sample, what are the host and port I should use for Odoo online?

Fausto R.
on 11/28/14, 10:29 AM

Sorry, I don't know this script is local...

Versão Integral, Anabela Damas
on 11/28/14, 10:35 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 11/28/14, 9:43 AM
Seen: 1707 times
Last updated: 3/16/15, 8:10 AM