E Invoice Error - UnboundLocalError: local variable 'res' referenced before assignment

Hi,

I get the following error when I click on Generate IRN button:

Any thoughts about what I am doing wrong?

Thanks

Jay

Exception:
Traceback (most recent call last):
File “/home/abcco/frappe-bench/apps/erpnext/erpnext/regional/india/e_invoice/utils.py”, line 899, in make_request
res = make_post_request(url, headers=headers, data=data)
File “/home/abcco/frappe-bench/apps/frappe/frappe/integrations/utils.py”, line 42, in make_post_request
return make_request(“POST”, url, **kwargs)
File “/home/abcco/frappe-bench/apps/frappe/frappe/integrations/utils.py”, line 34, in make_request
raise exc
File “/home/abcco/frappe-bench/apps/frappe/frappe/integrations/utils.py”, line 26, in make_request
frappe.flags.integration_request.raise_for_status()
File “/home/abcco/frappe-bench/env/lib/python3.8/site-packages/requests/models.py”, line 943, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: for url: https://gsp.adaequare.com/enriched/ei/api/invoice

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/abcco/frappe-bench/apps/erpnext/erpnext/regional/india/e_invoice/utils.py”, line 1004, in generate_irn
res = self.make_request(“post”, self.generate_irn_url, headers, data)
File “/home/abcco/frappe-bench/apps/erpnext/erpnext/regional/india/e_invoice/utils.py”, line 907, in make_request
return self.make_request(request_type, url, headers, data)
File “/home/abcco/frappe-bench/apps/erpnext/erpnext/regional/india/e_invoice/utils.py”, line 909, in make_request
self.log_request(url, headers, data, res)
UnboundLocalError: local variable ‘res’ referenced before assignment

Did you set the client ID and client secret (to be sourced from Adaequare) in e-Invoice settings or site_config.json? Refer for detailed instructions:
[E-Invoicing][India][Guide] Setup Adequare GSP's E-Invoicing Services in ERPNext

The 403 Client Error you’re seeing is generally because you were Forbidden from accessing the resource at the specified endpoint.

For self hosted systems, the Client ID and Secret needs to be entered into the common_site_config.json I think and it’s been entered in there. I’m suspecting I’m missing something in the client’s GST accounts.

Will review that soon and report back.

Thanks

Jay

I checked and ensured that the GST API User is appropriate. However, I am still getting the same error. The E Invoice Request Log is attached. Does that give anyone any hint as to where the problem could be please?

Thanks

Jay

I feel stupid, but when I was setting up the API user on Adaequare, I set it up for Staging and not Live. Once the API user was setup for the live system and the Client ID and Secret updated, it started working like a charm.

Thanks to @snv for his attention and helpful inputs.

Jay