Forums

HTTP Response Empty

I have set up an API that almost works perfectly. I POST a video to the server and GET a text file from it. Locally it works great, but now that I have this set up on PythonAnywhere, only the POST works. The user side is supposed to have a HTTPResponseMessage with a text file in it that they receive, but there is no response. Do I need to change my code in order to receive a response from PythonAnywhere? I'm sorry if this is a dumb question, I am a newbie and don't know where to look.

Code below is in C#. "MYSITE" is just a placeholder for me to post here

var response = await client.PostAsync("http://MYSITE.pythonanywhere.com", multipartFormContent);
var animation_data = await response.Content.ReadAsStringAsync();

[edit by admin: formatting]

Check in your code that you are actually returning a response. You can add debug prints to your code to see what is happening. Prints to stderr will appear in your error log.

I am getting a response? I guess. In the access log, I get this line...

1**.*.***.*** - - [22/Sep/2022:18:30:41 +0000] "GET /uploads/AnimationFile.txt HTTP/1.1" 404 207 "-" "-" "1**.*.***.***" response-time=0.005

And then on the user side, it does receive a text file, but instead of receiving the proper data, it receives the following.

<!doctype html>
<html lang=en>
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>

So, I guess I don't know what that means in this regard. How can the URL not be found if I just posted to it a few lines before?

As for your debugging suggestion using print, how can I debug a return line in Python?

return redirect(url_for('download_file', name="AnimationFile.txt"))

And sorry again if these are dumb questions, I'm fairly new to this.

Make sure that the path exists and the file is actually there. This could be also a static files mapping issue. Also, check your web app's error log, if you haven't done it yet.

I'm getting some "OSError : Write Error"s. The path does exist and now I seem to having troubles connecting to the API, my process starts to time out.

What happens if you manually do the kind of POST request that you're trying to do from your C# code? You could put together a simple HTML page that you could load locally, and then check out what's going out and what's coming back in the browser's developer tools console.