1919##
2020
2121import os
22+ import urllib .parse
2223import xmlrpc .client
2324
25+ import requests
26+
2427from pyodoo .v12 import Model
2528
2629
@@ -44,11 +47,28 @@ def get_authentication_from_demo() -> dict[str, str]:
4447 except (xmlrpc .client .Fault ,
4548 xmlrpc .client .ProtocolError ):
4649 # Sometimes the free public server start page is not available
47- # Use a specif instance (this may be very mutable)
48- info = {'host' : 'https://demo6.odoo.com' ,
49- 'database' : 'demo_saas-163_d08cf84b6242_1687720660' ,
50- 'user' : 'admin' ,
51- 'password' : 'admin' }
50+ info = {}
51+ # Follow the redirects from https://demo.odoo.com/
52+ request = requests .get ('https://demo.odoo.com/' )
53+ if request .status_code == 200 :
54+ # Process all the previous redirects to get the credentials
55+ for request in request .history :
56+ parse_result = urllib .parse .urlparse (url = request .url )
57+ if parse_result .query :
58+ qs = urllib .parse .parse_qs (qs = parse_result .query )
59+ if 'dbname' in qs :
60+ info = {'host' : f'{ parse_result .scheme } ://'
61+ f'{ parse_result .netloc } ' ,
62+ 'database' : qs ['dbname' ][0 ],
63+ 'user' : qs ['user' ][0 ],
64+ 'password' : qs ['key' ][0 ]}
65+ break
66+ if not info :
67+ # Use a specific instance (this may be very mutable)
68+ info = {'host' : 'https://demo6.odoo.com' ,
69+ 'database' : 'demo_saas-163_845e0736dbcc_1687729511' ,
70+ 'user' : 'admin' ,
71+ 'password' : 'admin' }
5272 return info
5373
5474
0 commit comments