question

dreadwolf avatar image
dreadwolf asked

ResetPassword python POST request has incorrect encoding.

I'm writing a python script (Can't use the python sdk because the server I'm using is not configured for Python 3) that calls the PlayFab reset password api. I am purposely calling the api with a bogus token and password so that I can test my error handling code. When I run the script using my computer as a local host it works fine and Playfab returns an error json as expected. When I test the api call in Postman using the same parameters it also works fine. But when I upload the script to the actual google cloud server it's supposed to run on, the content of the response I get back from Playfab is a garbled mess and can't be json decoded:

u'E\\ufffdK\\n\\ufffd@\\x10\\ufffd\\ufffd4\\ufffd\\x0e\\ufffd\\ufffd\\x10\\ufffd\\ufffd\\ufffdR\\x17\\ufffd\\x0b\\x0cNa\\ufffd0m\\ufffd{@\\x10\\ufffd\\ufffd$\\x04\\ufffd\\ufffd\\ufffd\\ufffd\\ufffd\\ufffd\\x10\\x0f\\ufffd\\ufffdeY\\ufffd\\ufffd\\ufffd\\ufffd\\ufffd\\ufffd\\ufffd\\ufffd;\\ufffd\\x045.\\x181J\\ufffd\\ufffd!\\ufffd\\ufffd\\ufffd\\x0b\\ufffd,\\u041b\\ufffd\\ufffd3n\\ufffdiQ\\ufffd\\ufffdn\\ufffd\\ufffd\\nU\\ufffd\\ufffd2\\ufffd\\x03\\ufffd\\u63aa\\ufffd\\ufffd\\ufffdS\\ufffd\\ufffd1\\ufffd\\ufffd\\x0c\\x051\\ufffd\\x0c\\ufffd\\ufffd\\ufffd\\x07'

This the code as I originally wrote it:

parameters = {'Password':password,'Token':token} 
headers = {'Content-Type': 'application/json','X-SecretKey':secretKey}
playFabResponse = requests.post(url = apiUrl, json = parameters,headers = headers

try: 
 json = playFabResponse.json() 
 response = flask.jsonify(json) 
except: 
  #I get a json parsing exception on google cloud only

This is the current state of my code. I've experimented with several ways of calling the post function and have tried adding many different headers, and nothing I've tried works.

parameters = dumps({'Password':password,'Token':token}) 
headers = {'Content-Type': 'application/json','Accept-Encoding':'gzip, deflate','X-SecretKey':secretKey,'X-ReportErrorAsSuccess':'true','X-PlayFabSDK':'PythonSdk-0.0.190410'} 
playFabResponse = requests.post(apiUrl,data = parameters,headers = headers) 

I've also tried these:

playFabResponse.encoding = 'utf-8'
playFabResponse.encoding = 'ascii'

And this:

#throws an exception on google cloud only
responseWrapper = json.loads(playFabResponse.content.decode("utf-8"))

I printed out a good response and a bad response and I analyzed the diff and there are a few notable differences:

Good: playFabResponse.apparent_encoding = 'ascii'

Bad: playFabResponse.apparent_encoding = 'ISO-8859-8'

Good: playFabResponse.headers = {'content-encoding': 'deflate' ...

Bad: 'content-encoding' is missing from headers

I'm not sure if this is an issue with my google cloud configuration, the way I'm calling the post function and reading the response, or if this is an issue on the PlayFab side. I've been stuck on this for many hours now and I'd appreciate some fresh ideas. Thanks.

apissdks
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dreadwolf avatar image dreadwolf commented ·

By the way, I tried the api call with a valid token. The request was successful and I got a status code of 200 but I am unable to decode the content of the response. I can work with only the status code but it's not ideal because I can't display detailed error messages to the user.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ dreadwolf commented ·

We cannot reproduce your issue but it seems to be a decode/encode issue, there is a related issue I found: https://github.com/googleapis/google-cloud-python/issues/2928.

In addition, you can change the content-type in the request:

Content-Type = application/json; charset=utf-8

You can also use RESTful API testing tools like Postman and make sure your request and response configuration are exactly the same: https://api.playfab.com/sdks/postman

As far as I concern, this is a Google Cloud Server issue and is beyond our supporting scope.

0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.