profusion / sgqlc

Simple GraphQL Client
https://sgqlc.readthedocs.io/
ISC License
506 stars 85 forks source link

'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte #221

Closed nikorose87 closed 1 year ago

nikorose87 commented 1 year ago

Specific payload makes the http.py fails in line 162:

{
  "errorMessage": "'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte",
  "errorType": "UnicodeDecodeError",
  "stackTrace": [
    "  File \"/var/task/main.py\", line 79, in notifications\n    __response = notifier.run()\n",
    "  File \"/var/task/apps/notifier.py\", line 306, in run\n    __invoke = __invoke_fun()\n",
    "  File \"/var/task/apps/notifier.py\", line 58, in subscriptions\n    response = getattr(\n",
    "  File \"/var/task/environment/subscriptions.py\", line 130, in message\n    return self.send_mutation(query, variables)\n",
    "  File \"/var/task/environment/subscriptions.py\", line 91, in send_mutation\n    data = endpoint(query, variables)\n",
    "  File \"/opt/python/sgqlc/endpoint/http.py\", line 162, in __call__\n    body = f.read().decode('utf-8')\n"
  ]
}

The headers are the following:

{'Content-Type': 'application/json', 'sid': 'System.Messages', 'authorization': 'new_session', 'User-Agent': 'Mvnifest Business API', 'Accept': '/', 'Host': 'j35nodq4hvcq7nsxfd3e3eb67q.appsync-api.us-west-2.amazonaws.com', 'Accept-Encoding': 'gzip, deflate, br', 'Connection': 'keep-alive', 'Content-Length': 410}

The variables are:

{'channel': 'bd5cac43-f1d7-428b-a9e7-f0a6973ecc1a', 'event': 'creationSummary', 'payload': '{"orders_qty": 12, "total_units": 16, "can_be_processed_qty": 9, "can_not_be_processed_qty": 3, "can_be_processed": [{"identifier": "TBD", "order_number": "23409", "status": "Success"}, {"identifier": "TBD", "order_number": "23421", "status": "Success"}, {"identifier": "TBD", "order_number": "40658", "status": "Success"}, {"identifier": "TBD", "order_number": "88790", "status": "Success"}, {"identifier": "TBD", "order_number": "5674", "status": "Success"}, {"identifier": "TBD", "order_number": "789", "status": "Success"}, {"identifier": "TBD", "order_number": "638", "status": "Success"}, {"identifier": "TBD", "order_number": "456", "status": "Success"}, {"identifier": "TBD", "order_number": "4562", "status": "Success"}], "can_not_be_processed": [{"identifier": "TBD", "order_number": "40657", "status": "Missing bill to attention in row 4, "}, {"identifier": "TBD", "order_number": "40678", "status": "Missing warehouse in row 5, Missing shipping method in row 5, "}, {"identifier": "TBD", "order_number": "387", "status": "Missing first ship date in row 15, "}]}', 'context': 'orders'}

The query:

             mutation message($event:String $channel:String! $payload:String $context:String ) {
               new_message : message( channel:$channel event:$event payload:$payload context:$context ) {
                        __typename
                        channel
                        event
                        payload
                        context
                    }
                }

🐜 Bug Report

The passed variables to the HTTP request are throwing the error:

"'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte"

Expected Behavior

I expected the regular subscription sent by the code.

Current Behavior

I do not know why this error is caused by this payload. If I delete the payload it works, however, I do not see unexpected (or not allowed) characters that cant be decoded.

May you can help me to know which part of causing the error?

Related documentation

https://stackoverflow.com/questions/35122232/urllib-request-urlopen-return-bytes-but-i-cannot-decode-it

Thank you

nikorose87 commented 1 year ago

I just got rid of gzip in headers.