sendgrid / sendgrid-python

The Official Twilio SendGrid Python API Library
https://sendgrid.com
MIT License
1.55k stars 714 forks source link

400 Bad Request error when trying to post a segment #944

Closed mahimaaapatel closed 3 years ago

mahimaaapatel commented 4 years ago

Issue Summary

I am getting a Bad Request Error when trying to post a segment using the API. The get function is working but post is not.

Code Snippet

 data = {
        "name" : "hello",
        "parent_list_id" : "3146ca27-25da-4fe9-8210-162a5e6872d3",
        "query_dsl": "email LIKE 'gmail.com'"
}
    headers = {'Accept': 'application/json'}
    try:
        response = sg.client.marketing.segments.post(request_headers=headers, request_data=data)
        print(response.status_code)
        print(response.body)
        print(response.headers)
    except Exception as e:
        print (e.to_dict)

Exception/Log

{'errors': [{'field': 'json.decode failed', 'message': 'error: EOF, body: Not Logging for PII Compliance!'}]}

Technical details:

childish-sambino commented 4 years ago

Change request_data to request_body?

eshanholtz commented 3 years ago

Closing due to inactivity. Please reopen if your issue still needs to be addressed.