Forums

API Request is getting Failed

Hi I am testing the API request for web app as per the doc: https://docs.cleartax.in/cleartax-for-developers/e-invoicing-api/e-invoicing-api-reference/cleartax-e-invoicing-apis-xml-schema

Request URL: https://einvoicing.internal.cleartax.co/v2/eInvoice/generate Request Method: PUT

I am getting below error:

2021-08-07 13:30:49,634: Exception on /upload [POST]
Traceback (most recent call last):
  File "/home/santoshmohan04/.virtualenvs/einvoice/lib/python3.6/site-packages/flask/app.py", line 2070, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/santoshmohan04/.virtualenvs/einvoice/lib/python3.6/site-packages/flask/app.py", line 1515, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/santoshmohan04/.virtualenvs/einvoice/lib/python3.6/site-packages/flask/app.py", line 1513, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/santoshmohan04/.virtualenvs/einvoice/lib/python3.6/site-packages/flask/app.py", line 1499, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/santoshmohan04/einvoice/einvoice.py", line 55, in uploadFile
    url = "https://einvoicing.internal.cleartax.co/v2/eInvoice/generate"
  File "/usr/local/lib/python3.6/http/client.py", line 1287, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1333, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1282, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1042, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.6/http/client.py", line 980, in send
    self.connect()
  File "/usr/local/lib/python3.6/http/client.py", line 1440, in connect
    super().connect()
  File "/usr/local/lib/python3.6/http/client.py", line 952, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/local/lib/python3.6/socket.py", line 724, in create_connection
    raise err
  File "/usr/local/lib/python3.6/socket.py", line 713, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

kindly help me to test the api and build the app.

[edit by admin: formatting]

Free accounts have restricted Internet access; they can only access external sites via HTTP or HTTPS, are limited to sites on our whitelist, and have to make their requests through a proxy.

It looks like you're using Python's built-in HTTP module to make your requests; it has to be specifically configured to use a proxy. If you don't absolutely have to use that specific module, I recommend that you use the requests module instead -- it's much easier to use, and in particular it has proxy management built in so you don't need to do any special configuration.

I am using the requests Module and sending API request but its giving error. Its working fine in my localhost

Request sent:

import requests

url = "https://einvoicing.internal.cleartax.co/v2/eInvoice/download?template=62cfd0a9-d1ed-47b0-b260-fe21f57e9c5e&format=PDF&irns=817e1837fd2d0aa03a25b7ce792507f56c732dae231bbc2836c27f8f18cd6574"

payload={}
headers = {
  'x-cleartax-auth-token': '1.a3ab310f-6389-4fa3-b64b-bfe25a7fcbae_8fbbed62507b5709f3224c2144d2749d0660270d333673f4e6823a1b40098711',
  'x-cleartax-product': 'EInvoice',
  'Content-Type': 'application/json',
  'owner_id': 'e5e78c59-a3c6-4d59-8255-5c0816c11445',
  'gstin': '29AAFCD5862R000'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

Error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 696, in urlopen
    self._prepare_proxy(conn)
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 366, in connect
    self._tunnel()
  File "/usr/local/lib/python3.9/http/client.py", line 903, in _tunnel
    raise OSError(f"Tunnel connection failed: {code} {message.strip()}")
OSError: Tunnel connection failed: 403 Forbidden
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 573, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='einvoicing.internal.cleartax.co', port=443): Max retries exceeded with url: /v2/eInvoi
ce/download?template=62cfd0a9-d1ed-47b0-b260-fe21f57e9c5e&format=PDF&irns=817e1837fd2d0aa03a25b7ce792507f56c732dae231bbc2836c27f8f18cd6574 (Caused
 by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/santoshmohan04/test/test.py", line 14, in <module>
    response = requests.request("GET", url, headers=headers, data=payload)
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 510, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='einvoicing.internal.cleartax.co', port=443): Max retries exceeded with url: /v2/eInvoice
/download?template=62cfd0a9-d1ed-47b0-b260-fe21f57e9c5e&format=PDF&irns=817e1837fd2d0aa03a25b7ce792507f56c732dae231bbc2836c27f8f18cd6574 (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))

[formatted by admin]

einvoicing.internal.cleartax.co is not on the whitelist for free users. We are happy to whitelist open, documented APIs. Provide docs and we will consider it.

Find the link for API docmentation: https://docs.cleartax.in/cleartax-for-developers/e-invoicing-api/e-invoicing-api-reference/cleartax-e-invoicing-apis-xml-schema

Thanks, we've added einvoicing.internal.cleartax.co to the whitelist.

Please whitelist draft4sms api

API documentation link: https://text.draft4sms.com/Dashboard.php?page=apicode

API link : https://text.draft4sms.com/vb/apikey.php?

Hi, please request the addition to the whitelist here: https://help.pythonanywhere.com/pages/RequestingAllowlistAdditions