[Python] python requests GET returning HTTP 204

Discussão em 'Python' iniciado por Stack, Março 8, 2025.

  1. Stack

    Stack Membro Participativo

    I cannot wrap my brain around this issue:

    When I run this code in my IDE (pycharm), or via the command line, I get a 204 HTTP response and no content. When I set breakpoints in my debugger to see what is happening, the code executes fine and r.content and r.text are populated with the results from the request. r.status_code also has a value of 200 when running in the debugger.

    code:

    r = requests.post(self.dispatchurl, verify=False, auth=HTTPBasicAuth(self.user, self.passwd))
    print 'first request to get sid: status {}'.format(r.status_code)
    json_data = json.loads(r.text)
    self.sid = json_data['sid']
    print 'the sid is: {}'.format(self.sid)
    self.getresulturl = '{}/services/search/jobs/{}/results{}'.format(self.url, self.sid, self.outputmode)
    x = requests.get(self.getresulturl, verify=False, auth=HTTPBasicAuth(self.user, self.passwd))
    print 'second request to get the data: status {}'.format(x.status_code)
    print 'content: {}'.format(x.text)


    output when run through debugger:

    first request to get sid: status 201
    the sid is: sanitizedatahere
    second request to get the data: status 200
    content: {"preview":false...}

    Process finished with exit code 0


    When I execute the code normally without the debugger, i get a 204 on the second response.

    output:

    first request to get sid: status 201
    the sid is: sanitizedatahere
    second request to get the data: status 204
    content:

    Process finished with exit code 0


    I am guessing this has something to do with the debugger slowing down the requests and allowing the server to respond with the data? This seems like a race condition. I've never run into this with requests.

    Is there something I am doing wrong? I'm at a loss. Thanks in advance for looking.

    Continue reading...

Compartilhe esta Página