question

r-schatz avatar image
r-schatz asked

PlayFabHTTP Recieved an empty response

I am doing a call to SetTitleData from Python (playfab-0.0.200303). It invokes the failure callback with "PlayFabHTTP Recieved an empty response" but I can see the Key showing up properly on the PlayFab side in the UI. So the call is a success. Am I doing something wrong?

Code looks like this:

PlayFabSettings.TitleId = "..."
PlayFabSettings.DeveloperSecretKey = "..."


request = {
    "Key": "user-key-name",
    "Value": "{\"foo\": 1}"
}


def callback(success, failure):
    if success:
        # handle success
    else:
        # handle failure


PlayFabServerAPI.SetTitleData(request, callback)

The vanilla version of the SDK installed with pip is even missing an import for me.

Traceback (most recent call last):
  File "C:\Users\path\venv\lib\site-packages\playfab\PlayFabHTTP.py", line 75, in DoPost
    emptyResponseError.ErrorCode = PlayFabErrorCode.Unknown;
NameError: name 'PlayFabErrorCode' is not defined
10 |1200

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

Citrus Yan avatar image
Citrus Yan answered

For the “NameError” issue, changing the code in PlayFabHttp.py, line 75, to the following should fix it:

emptyResponseError.ErrorCode = PlayFabErrors.PlayFabErrorCode.Unknown

which I suppose is also how you fixed it.

Diving deeper, we found that the response received from PlayFab is actually ok, which is :

{'code': 200, 'status': 'OK', 'data': {}}

However, what’s wrong is how PythonSDK handles it:

1) In PlayFabHTTP.py line 51:

response = responseWrapper["data"]

under the current situation, it will pass {} to response.

2)Then in line 62:

elif response and callback:

The statement above will be evaluated as false because the response variable, which is {}, will be evaluated as false by Python during runtime.

3) Therefore, code will enter into the last conditional block, starting from line 69, which explains the current behaviors of the PythonSDK.

4)In Summary, response with no content shouldn’t be considered as empty response. To solve this, a possible solution would be:

•Change line 62 “elif response and callback: “ to “ elif (response or response == {}) and callback:”

•Change the user defined callback to something like this:

def callback(success, failure):  

if success or success == {}: 

#handle success  

else:  

#handle failure

I will report this to the SDK team to help fixing it, sorry for the inconvenience.

1 comment
10 |1200

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

franklinchen avatar image franklinchen commented ·

Hi @r-schatz, the fix has been submitted, the deploy will be executed soon, thanks.

0 Likes 0 ·
r-schatz avatar image
r-schatz answered

Awesome. Thanks for the help.

1 comment
10 |1200

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

franklinchen avatar image franklinchen commented ·

The fix has been deployed to the latest SDK

0 Likes 0 ·

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.