PATCH On Session throwing AttributeError: 'str' object has no attribute 'items'

5
closed
dprevost-LMI
dprevost-LMI
Posted 10 months ago

PATCH On Session throwing AttributeError: 'str' object has no attribute 'items' #314

Hi,

I have changed a Patch Request by a PATCH On Session and now my test throws AttributeError: 'str' object has no attribute 'items'

Here a screenshot of the Robot output image

Previsouly my code was:

${resp}=                  Patch Request             blockfilter    ${path}    data=${data}    headers=${headers}

now it is

${resp}=                  Patch On Session         blockfilter    ${path}    json=${data}    headers=${headers} expected_status=any

the data should have been well resolved from the log: image

The only way my test is referring to 'items' is because of the value passed for the path which uses ${items.json()['items'][0]['id']}

${my_id}=     ${items.json()['items'][0]['id']}
${path}=                  Set Variable             ${api_user_settings}/my-filters/${my_id}

So when using an expression in the path like ${items.json()['items'][0]['id']} while using Patch On Session, it seem to be problematic while when using Patch Request it is working fine

lucagiove
lucagiove
Created 10 months ago

I've reproduced the error by passing a string as headers, it should be a dictionary.

dprevost-LMI
dprevost-LMI
Created 10 months ago

@lucagiove On my side, my tests are using dictionary for the header part:

${headers}=               Create Dictionary        Content-Type=application/json        Authorization=Bearer ${token}
lucagiove
lucagiove
Created 10 months ago

Please run the test with --loglevel trace and look at the data passed to the keyword

dprevost-LMI
dprevost-LMI
Created 10 months ago

Thanks will try tomorrow

dprevost-LMI
dprevost-LMI
Created 9 months ago

Ohhhh there was a missing space before expected_status=any in

Patch On Session blockfilter ${path} json=${data} headers=${headers} expected_status=any

It would be cool to have a better error message than AttributeError: 'str' object has no attribute 'items'

The call stack is below if it can help to have a better message:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/RequestsLibrary/utils.py", line 138, in decorator
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/RequestsLibrary/RequestsOnSessionKeywords.py", line 106, in patch_on_session
    response = self._common_request("patch", session, url,
  File "/usr/local/lib/python3.9/site-packages/RequestsLibrary/SessionKeywords.py", line 569, in _common_request
    resp = method_function(
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 602, in patch
    return self.request('PATCH', url, data=data, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 516, in request
    prep = self.prepare_request(req)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 449, in prepare_request
    p.prepare(
  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 315, in prepare
    self.prepare_headers(headers)
  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 447, in prepare_headers
    for header in headers.items():