Odoo Help


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

Fausto R.
on 11/28/14, 9:43 AM 2,700 views

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
  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
  File "/usr/lib/python2.7/httplib.py", line 997, in endheaders
  File "/usr/lib/python2.7/httplib.py", line 850, in _send_output
  File "/usr/lib/python2.7/httplib.py", line 812, in send
  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,




Anabela Damas

--Anabela Damas--

| 6 7 7
Aveiro, Portugal
--Anabela Damas--
IT Consultant
Anabela Damas
On 11/28/14, 10:00 AM


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._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(


if __name__ == "__main__":

#(host, port, username, password, dbname)
    testobj = TestClient("", "8069", "admin", "123qwe", "database")
    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

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


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