Accessing ERPNext info through REST API using python

Hello Community Members,

I am trying to access ERPNext through rest api using requests module of python, using below code:

import requests
r = requests.get(‘http://myurl/login’, data = {‘usr’:‘administrator’, ‘pwd’:‘ab@134’})
print “============”, r.json, r.url

I am not able to login into the system, am I doing something wrong ? Please guide if some one has experience in this same area.

I am looking to fetch information from ERPNext through rest api and would like to get response in JSON format.

hi bharat, think you should login first using post request then you can use get to retrive data.
reading from

r =‘http://myurl/api/method/login’, data = {‘usr’:‘administrator’, ‘pwd’:‘134’})

gave response 200, which is OK according to HTTP status.

a = requests.get(‘http://myurl/api/method/frappe.auth.get_logged_user’)

gives 403, which is Forbidden according to HTTP status.

Am i missing something ? Due to this I think i cannot read through records. Any help is much appreciated.

Any help on this please.

Use frappe-client frappe-client/ at master · frappe/frappe-client · GitHub

Hi max,

Thanks for the pointer. Any example will be more helpful which uses frappe-client, would you please let me know if possible ?

@bharat in the main directory has some examples

frappe-client/ at master · frappe/frappe-client · GitHub

Hi max,

Got that!

Thanks for the help.

I’m stucked at same isse, ie login status=200 but for confirmation, 403 error.
Any suggestions ?