sendgrid/sendgrid-python

Getting python_http_client.exceptions.ForbiddenError: HTTP Error 403: Forbidden when hitting marketing endpoints

rastro-dev opened this issue · 1 comments

Issue Summary

Hi there, this is my first github issue, so please bear with me. Anyhow I am getting "python_http_client.exceptions.ForbiddenError: HTTP Error 403: Forbidden" when I use the sendgrid client to hit marketing api endpoints. I can use the same key to all Email related endpoints just fine. I can also use curl on the marketing api endpoints with the same key and they all work. I can also use the same key on this page for example "https://sendgrid.api-docs.io/v3.0/lists/get-all-lists" and it will work fine. So I know its not the key. I have also tried to load the key either through environment var or directly passed to the constructor - Neither worked. I am hoping that someone might have an idea as to what I am missing here. Thanks

Code Snippet

Here is an example of using a code snippet from the libs examples.

import sendgrid
import os

sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))

response = sg.client.contactdb.lists.get()
print(response.status_code)
print(response.body)
print(response.headers)

Exception/Log

Traceback (most recent call last):
  File "/home/macfreak/sg-test.py", line 8, in <module>
    response = sg.client.contactdb.lists.get(query_params=params)
  File "/home/macfreak/.local/lib/python3.8/site-packages/python_http_client/client.py", line 277, in http_request
    self._make_request(opener, request, timeout=timeout)
  File "/home/macfreak/.local/lib/python3.8/site-packages/python_http_client/client.py", line 184, in _make_request
    raise exc
python_http_client.exceptions.ForbiddenError: HTTP Error 403: Forbidden

Technical details:

  • sendgrid-python version: '6.8.2'
  • python version: 3.8.10

I found the issue and it seems that there is a problem with the example code. All I had to do is change the documentation and tests example from "response = sg.client.contactdb.lists.get()" to "response = sg.client.marketing.lists.get()". The unfortunate part is that this issue is present in the python, php and ruby docs.