PagerDuty / pdpyras

Low-level PagerDuty REST/Events API client for Python
MIT License
129 stars 29 forks source link

Fix unsupported format character 'B' #103

Closed av1m closed 1 year ago

av1m commented 1 year ago

I get this error : ValueError: unsupported format character 'B' (0x42) at index 61

Stacktrace :

File .venv/lib/python3.11/site-packages/pdpyras.py:1849, in APISession.iter_all(self, url, params, paginate, page_size, item_hook, total)
   1846     return
   1848 # Make the request and validate/unpack the response:
-> 1849 r = successful_response(
   1850     self.get(url, params=data.copy()),
   1851     context='classic pagination'
   1852 )
   1853 body = try_decoding(r)
   1854 results = unwrap(r, wrapper)

File .venv/lib/python3.11/site-packages/pdpyras.py:859, in successful_response(r, context)
    847 def successful_response(r: requests.Response, context=None) \
    848         -> requests.Response:
    849     """Validates the response as successful.
    850 
    851     Returns the response if it was successful; otherwise, raises an exception.
   (...)
    857     :returns: The response object, if it was successful
    858     """
--> 859     message = http_error_message(r, context=context)
...
    788         f"{endpoint}: Success (status %d) but an expectation still " \
    789         f"failed{context_msg}"
    790     )%(r.status_code)

ValueError: unsupported format character 'B' (0x42) at index 61

The actual code mix f-string and %d. This occurs the ValueError. I just change the code to use f-string.

allisonsuarez commented 1 year ago

I am seeing this error too, can we get it fixed?

alex-astronomer commented 1 year ago

Also seeing this affecting our production environment. @Deconstrained anything I can do to get this moving?

Deconstrained commented 1 year ago

Thank you and pardon the late response!

av1m commented 1 year ago

Thank you for your approval. It would be good to update pdpyras to 5.0.2 @Deconstrained

Deconstrained commented 1 year ago

v5.0.2 which was uploaded to pypi earlier includes this fix. Afterwards I went through and found/replaced similar unsafe mixing of f-strings and printf-style strings so the generic issue is fixed and shouldn't come up again (this is in v5.0.3)