Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid TypeError: must be str, not bytes when the request fails #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xrobin
Copy link

@xrobin xrobin commented Jul 3, 2023

I have been seeing the following (non reproducible) error message from time to time with the fasta.py script:

Traceback (most recent call last):
  File "fasta.py", line 848, in <module>
    getResult(jobId)
  File "fasta.py", line 471, in getResult
    clientPoll(jobId)
  File "fasta.py", line 455, in clientPoll
    result = serviceGetStatus(jobId)
  File "fasta.py", line 382, in serviceGetStatus
    printDebugMessage(u'serviceGetStatus', u'status: ' + status, 2)
TypeError: must be str, not bytes

The restRequest function returns a str when the request succeeds. When the request fails, an additional call to requests.get(url) is performed, and the raw response .content is returned as bytes instead, without conversion.

This PR converts the content to a str also in case of failure.

PS: not sure if returning the error contents is the right thing to do in this context, but that's an other story.

This prevents a TypeError: must be str, not bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant