Skip to content

HTTP Error 401:Unauthorized with Cronjob #835

Description

@asing012

Hey guys! I am getting the HTTP Error 401. It works fine when I directly run the code. But I am trying to automate it using cronjob on Ubuntu and it keeps giving me this error. I have also tested my API key by sending a request to "https://sendgrid.com/docs/for-developers/sending-email/curl-examples/#-Hello-World".

Any help would be appreciated!

Traceback (most recent call last):
File "/home/akshay/.local/lib/python3.6/site-packages/python_http_client/client.py", line 172, in _make_request
return opener.open(request, timeout=timeout)
File "/usr/lib/python3.6/urllib/request.py", line 532, in open
response = meth(req, response)
File "/usr/lib/python3.6/urllib/request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.6/urllib/request.py", line 570, in error
return self._call_chain(*args)
File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/usr/lib/python3.6/urllib/request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: Unauthorized

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "./apicall.py", line 46, in 
response = sg.send(message)
File "/home/akshay/.local/lib/python3.6/site-packages/sendgrid/sendgrid.py", line 98, in send
response = self.client.mail.send.post(request_body=message.get())
File "/home/akshay/.local/lib/python3.6/site-packages/python_http_client/client.py", line 252, in http_request
return Response(self._make_request(opener, request, timeout=timeout))
File "/home/akshay/.local/lib/python3.6/site-packages/python_http_client/client.py", line 174, in _make_request
exc = handle_error(err)
File "/home/akshay/.local/lib/python3.6/site-packages/python_http_client/exceptions.py", line 82, in handle_error
exc = err_dicterror.code
File "/home/akshay/.local/lib/python3.6/site-packages/python_http_client/exceptions.py", line 10, in init
self.body = error.read()
File "/usr/lib/python3.6/tempfile.py", line 624, in func_wrapper
return func(*args, **kwargs)
File "/usr/lib/python3.6/http/client.py", line 462, in read
s = self._safe_read(self.length)
File "/usr/lib/python3.6/http/client.py", line 614, in _safe_read
raise IncompleteRead(b''.join(s), amt)
http.client.IncompleteRead: IncompleteRead(0 bytes read, 116 more expected)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "./apicall.py", line 49, in 
print(e.message)
AttributeError: 'IncompleteRead' object has no attribute 'message'

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty: easyfix is easy in difficultystatus: work in progressTwilio or the community is in the process of implementingtype: questionquestion directed at the library

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions