TDResources WebClient KeyError

Hi! trying to handle callback from API and get error. Same request through op().request works. Idk it might be related to statusCode 100.

Example request:
op.TDResources.WebClient.Request(callback, url, "POST", data=payload_json)

Traceback (most recent call last):
  File "/sys/TDResources/webClient/webclient1_callbacks", line 2, in onResponse
  File "/sys/TDResources/webClient/WebClientExt", line 74, in onWebResponse
KeyError: 17

Hi @olegchomp,

thanks for the report, we are having a look at it.
What build are you using?

cheers
Markus

@snaut
I am pretty sure they are hitting a 300 or 100 status code which is empty, but has the correct id. In line 75 you are deleting the entry. So when the actual response after the redirect comes in, you have an empty dict and a key-error.
My webclient simply does the following until I have something better to do with the 100 & 300 responses.

		if statusCode < 200 and 300 <= statusCode < 400: 
			self.log("Ignoring Response", statusReason)
			return

Hey @alphamoonbase,

yup, the request id is currently deleted upon the first response so redirects create this error as this is not handled in the TDResources.

cheers
Markus

@olegchomp,

this will be fixed in the next 2023.10k release.

cheers
Markus

Hey! With the newest 2023.10k release I’m getting an odd behavior. Could it be related to these recent changes and fixes?

I’m using TDResources.WebClient.Request the same way @olegchomp was using (I’ve derived my code from his basically).

My callbacks through WebClient now return None for status code, headerdict and data. Doing the same call from webclient dat instead of TDResources retrieves the data correctly. I’ve changed nothing, only opened my project with the new version.
Am I misunderstanding something, how do I handle this?

Hi @aulerius,

sorry, I’ve made a mistake in the code and didn’t check it. This will be fixed in the next release.

cheers
Markus

1 Like

Hi! Just tested new realease and issue still exist. Here is print(statusCode) from /sys/TDResources/webClient/

{'code': 100, 'message': 'Continue'}
b''
b''
Expecting value: line 1 column 1 (char 0)
{'code': 200, 'message': 'OK'}
Traceback (most recent call last):
  File "/sys/TDResources/webClient/webclient1_callbacks", line 15, in onResponse
  File "/sys/TDResources/webClient/WebClientExt", line 76, in onWebResponse
KeyError: 50

and here is only print(statusCode) in onWebResponse:

{'code': 100, 'message': 'Continue'}
{'code': 200, 'message': 'OK'}
None

i’m not sure if it good solution, but if i remove del line in onWebResponse, everything ok

del(self.Callbacks[id])

Hi @olegchomp,

ah sorry - I see - I’m not dealing with the 100 response - should have caught that!
will fix.

cheers
Markus