SmartGridready / SGrPython

Development of SGr PyPi package
Other
1 stars 1 forks source link

Can't authenticate due to the mismatched request body definition #26

Closed d1msk1y closed 3 months ago

d1msk1y commented 3 months ago

Using the example_generic.py, when trying to connect to the rest API, a 500 error is received.

As I figured it out, when sending the /authenticate post request, its body is defined as data: https://github.com/SmartGridready/SGrPython/blob/c3aeabdaefbc777d54214f75775c549319a62cf7/sgr_library/restapi_client_async.py#L139 However, according to the provided XML, we have to send a JSON body in order to properly authenticate, therefore, I had to define the body as json:

async with self.session.post(url=self.authentication_url, headers=self.headers, json=self.data) as res:
                                                                                ^^^^

Otherwise, the request body will contain single quoted property keys, thus the 500 error will occur.

Is this an unforeseen case, or the body must not be JSON? Either way, the solution with the provided XML will not work unless the body is defined as json.

Request body defined in the XML:

<requestBody>{"strategy": "local", "email": "{{username}}", "password": "{{password}}"}</requestBody>

Request body within the actual post request:

{'strategy': 'local', 'email': '<username>', 'password': '<password>'}