Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
2503 Widoki

how to configure api correctly on odoo cloud?

i did it on  prem and it work fine but on cloud it does not

here is my python code :

import xmlrpc.client

import pandas as pd

from tabulate import tabulate



# Odoo API information

url = 'myurl'

db = 'mydatabsename'

username = 'myuser​'

password = 'my api key'


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

common.version()

print(common.version())


uid = common.authenticate(db, username, password, {})

models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))


print(models)


try:

    # Change the model to 'sale.order.line' and adjust the query as needed

    records = models.execute_kw(

        db, uid, password, 'sale.order.line', 'search_read',

        [[('state', '=', 'sale')]],

        {'fields': ['id','order_id','product_template_id', 'product_id','display_name', 'product_uom_qty', 'price_unit', 'product_uom', 'write_date', 'name' ,'qty_delivered'],

         'limit': 100, 'order': 'write_date desc'}

    )


    # Extract relevant fields and flatten the data

    data = []

    for record in records:

        product_info = models.execute_kw(

            db, uid, password, 'product.product', 'read',

            [[record['product_id'][0]]],

            {'fields': ['name']}

        )[0]


        data.append({

            'Date': record['write_date'],

            'Sales Order Number': record['order_id'],

            'Product': record['name'],

            #'Product': product_info.get('name', ''),

            #'Product Full Name': record['display_name'],

            'Quantity': record['product_uom_qty'],

            'Price Per Unit': record['price_unit'],

            'Qty Delivered': record['qty_delivered']

            #'Unit': record['product_uom']

        })


    df = pd.DataFrame(data)


    # Print the table

    print(tabulate(df, headers='keys', tablefmt='fancy_grid', showindex=False))


    # Export to Excel file

    excel_file_path = 'sales_order_lines_with_details.xlsx'

    df.to_excel(excel_file_path, index=False)

    print(f"Sales order lines with details exported to {excel_file_path}")


except xmlrpc.client.Fault as e:

    print(f"Error executing Odoo API method: {e}")

finally:

    print("Script execution completed.")

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,
Here are some general steps you can take to troubleshoot and ensure proper configuration:

  1. Credentials Check:
    • Verify URL, database, username, and password correctness.
  2. API Access Rights:
    • Confirm the specified user has necessary API access rights.
  3. Update URL Handling:
    • Construct and pass the full API endpoint URL to ServerProxy.
  4. SSL Handling:
    • Handle SSL correctly, consider additional parameters for HTTPS.
  5. Print Responses:
    • Print responses, especially from common.authenticate, for error messages.
  6. Firewall and Security:
    • Ensure no restrictions in firewall or security groups.
  7. Version Compatibility:
    • Confirm script compatibility with the Odoo version on the cloud.
  8. Exception Handling:
    • Catch relevant exceptions for detailed error messages.
  9. Check Odoo Logs:
    • Inspect Odoo logs for API call-related errors or warnings

You can also refer to How to Handle External APIs in Odoo 16


Hope it helps

Awatar
Odrzuć
Autor Najlepsza odpowiedź

when i triger this 

  common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))common.version()print(common.version())

it give me :
{'server_version': '16.0+e', 'server_version_info': [16, 0, 0, 'final', 0, 'e'], 'server_serie': '16.0', 'protocol_version': 1}
but when i trigger the other script ,it give me only

Awatar
Odrzuć
Autor

<Fault 3: 'Access Denied'>

Autor

this script too in the video :
import xmlrpc.client

url = 'myurl_cloud_odoo'

db = 'db-test-10928066'

username = 'myuser'
password = 'myapi'

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

uid = common.authenticate(db, username, password, {})

if uid:
print("authentication success")
else:
print("authentication failed")

it give me authentication failed
so what is the permission needed to accept the api external on cloud
when i tried it on onprem it works perfect

Najlepsza odpowiedź

Hi,

When the script is triggered against the cloud server, did you receive any error ? Did you get chance to cross how far the code execution goes.

It will be better, if you update the post along with error details that you receive.

For more about odoo external api, see: external api in odoo

Thanks

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
mar 24
1155
1
maj 23
2280
1
lut 24
1876
0
sty 24
1311
0
sie 24
1700