Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

ProtocolError for localhost:8069/xmlrpc/2/common: 409

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
pythonapixmlrpcodoov15
2 Antwoorden
4885 Weergaven
Avatar
Ali Ammar

I write an API to create user in odoo database

if I enter username and password for existing user at first time I receive the message that i add in this case in second time i receive conflict message and status code and the server stop receive any thing what ever I request I receive conflict and the problem need restart the server 

any solution ??

my code:

 @http.route('/register',  auth="public",csrf=False, website=True, methods=['POST'],type="json")

    defregister(self,idd= None, **kw):

        un='perla'

        password1 = 'perla'

        db = 'perla'

        body = request.jsonrequest

        username = body['body']['username']

        password = body['body']['password']


        common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(self.url))

        print(common)

        g = True

        try:

            print('uid')
            uid = common.authenticate(db,un, password1, {})

            print(uid)

            print('uid')

        except:

            response = json.dumps({ 'jsonrpc': '2.0', 'message': 'Unauthorized!'})

            return Response(            response, status=401,            headers=[('Content-Type', 'application/json'), ('Content-Length', 100)]                )

           
        if(g== False):

            print("false")

            print(Response)

                     print('false 222 ')


            # return Response

            response = json.dumps({ 'jsonrpc': '2.0', 'message': 'Unauthordecfedceized!'})

            returnResponse(            response, status=401,            headers=[('Content-Type', 'application/json'), ('Content-Length', 100)]

                )

                    else:

            print("else")
            models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(self.url))

            print("EMP")

        try:

            print('try')

            is_there= models.execute_kw(self.db, uid, self.password, 'res.users', 'search_count', [[['login', '=', username]]])

            ifis_there :

                response=json.dumps({ 'jsonrpc': '2.0', 'message': 'This User is already exist'})

                Response.status = '409'

                returnresponse

            else :

                user_id = models.execute_kw(self.db, uid, password1, 'res.users', 'create', [{'name': username, 'password' : password, 'login' :username ,'sel_groups_1_9_10':9, 'sel_groups_25_26_27' : 26,'is_active' :False}])

            print('user_id' + str(user_id))


        exceptExceptionase :

                        response=json.dumps({ 'jsonrpc': '2.0', 'message': 'This User is already exist'})            Response.status = '409'

            return Response( response, status=409,            headers=[('Content-Type', 'application/json'), ('Content-Length', 100)]                )

        ifuser_id :

            date_now = str(datetime.today())

            print('date_now  >>>'  +str(date_now))


            payload = {                'id': user_id,

                'username': username, 

               'password': password,

                'login' :username ,

                'is_active':False,

                'timestamp' : date_now,}

            # user_details = '{"id" :"%s" , "username" : "%s" , "timestamp":"%s"}'  %(user_id ,username,date_now)

            SECRET='ali.ammar'

            enc = jwt.encode(payload, SECRET)

              new_user_id_count =models.execute_kw(self.db, uid, password1, 'user.token', 'search_count', [[['name' , '=', user_id]]])

              create_user_verification = models.execute_kw(self.db, uid, password1, 'user.verification', 'create', [{'name': user_id,'is_valid' : True}])

            print("create_user_verification" + str(create_user_verification))

            ifnew_user_id_count:

                models.execute_kw(self.db, uid, password1, 'user.token', 'write', [['name' , '=' , user_id], {'token': enc}])

            else :

                models.execute_kw(self.db, uid, password1, 'user.token', 'create', [{'name': user_id, 'token': enc }])

            uid=0

            return json.dumps({"details":payload})

                    else:

            return json.dumps({'Error': "Invalid credentials"})  

0
Avatar
Annuleer
Avatar
Ali Ammar
Auteur Beste antwoord

the error come from werkzeug.wrappers  when I set :

Response.status = '409' 

all Response will blocked 

the solution is in use :

 response = json.dumps({ 'jsonrpc': '2.0', 'message': 'This User is already exist!'})

 return Response(            response, status=409,headers=[('Content-Type', 'application/json'), ('Content-Length', 100)]        )  

0
Avatar
Annuleer
Avatar
Ahmed
Beste antwoord

hey...
first of all, you DON'T have to use XMLRPC to create new records in the odoo (the controller LIVE in side odoo) 
your can just use some thing like this:

@http.route('/create', auth='public')
    def index(self, **kw):
    s = http.request.env['hr.res'].sudo()
    vals ={
            'name':'bo mohamad',
            'password':'cola_bandora',
           }
    s.create(vals)
second of all, the table 'res.usres' is very sensitive to odoo, you can't create users programmatically.
odoo will redirect you with warning that you can only create users from configuration pannel (which is the res.users table)

0
Avatar
Annuleer
Ali Ammar
Auteur

the error is not come from create
it com from here uid = common.authenticate(db,un, password1, {})
after tow request it fail the server and go in conflict status

Ahmed

for that specific problem i can tell you this:
1- common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(self.url))
it's preferred to hold the URL of your database in a variable, because "self.url" can change from page to page. try 'localhost:8069' instead.
2- double check the authentication credentials (db , username and password)
3- remove try-catch statement or print the error to have more visual on the error messages
4- avoid using json.dumps and mush as possible. odoo will use this function any way ander the hood for you.

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
Error with call to external API
python api odoo
Avatar
Avatar
1
aug. 25
2415
what is the different between @api.model adn @api.model_create_multi in odoo 15? Opgelost
api odoo v15
Avatar
Avatar
1
okt. 22
7378
I need to update new field which i have added by the inheritance automatically in odoo15 Opgelost
python odoo v15
Avatar
Avatar
2
jul. 22
2853
API attachment question
python api xmlrpc
Avatar
Avatar
Avatar
Avatar
3
jun. 22
7569
haw create action with xmlrpc odoo 14?
python xmlrpc odoo
Avatar
Avatar
1
mei 22
4111
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now