How to fix error 500. POST method not working

Hello friends! Could you please help me deploy my artificial intelligence model on Glitch server? My model works perfectly on my computer when I run the local server using the command ‘python app.py’, but when I uploaded my model to Glitch hosting and installed all the necessary libraries, I faced an issue that Glitch does not support the POST method.

You can check it yourself, here is my AI model for predicting the cost of transporting cargo from point A to point B considering the weight of the cargo.

app.py

hidden

client.py

hidden

data.csv

cargo,cost,distance
100,200,10
200,400,20
300,600,30
400,800,40
500,1000,50

dataframe.py

import pandas as pd

Define the data as a dictionary

data = {
‘distance’: [10, 20, 30, 40, 50],
‘cargo’: [100, 200, 300, 400, 500],
‘cost’: [200, 400, 600, 800, 1000]
}

Create a pandas DataFrame from the dictionary

df = pd.DataFrame(data)

Save the DataFrame as a CSV file

df.to_csv(‘data.csv’, index=False)

my_model.py

hidden

predict.py

from app import get_distance

start = ‘10005’
end = ‘10006’

distance = get_distance(start, end)

print(“The distance between {} and {} is {} miles”.format(start, end, distance))

start.sh

python app.py

index.html

HTML here:

https:// chip-nine-wallflower.glitch . me/

(remove spaces)

I sat for 15 hours in a row in this project but did not figure it out. imma going to sleep. I am hope for your help!

:face_with_head_bandage:

can you open the logs to see if Glitch is actually running your app? I think it needs to have a requirements.txt file to recognize it as a python project.

Hello! Yes, I also have this file. Nothing in the logs, no errors. My model just doesn’t work, look here

https://chip-nine-wallflower.glitch.me/

It throws an error, but there is nothing in the logs

I filled in some dummy data and got a 500 error. so it seems you’ve gotten past the 405 issue?

Yes, now there is a 500 error. I still can’t find a solution to the problem. There is nothing in the logs

look in the HTTP response body

There is only such an error in the console, which I can not solve in any way

POST https://chip-nine-wallflower.glitch.me/predict 500

:face_exhaling:

Hmm, I uploaded the model.pkl file. But for some reason it appears in the “Assets” section and I cannot transfer it to the root directory. How can this problem be solved in Glitch? :eyes:

here’s some instructions for getting it into the project from assets. not sure if a .pkl file will show in the editor, but it’ll still be there

Hello! I have uploaded the file model.pkl to the root directory, but unfortunately it did not help to solve the problem, as I still get a 500 error. Maybe I am doing something wrong?

I’m getting "unsupported pickle protocol: 3" in the error details.

see if you can get that to show up in your network inspector. it looks like you have a filter only showing “Other” requests, you may have to clear that to show the request to /predict

I found what the problem is, this is a problem on the Glitch side. The thing is, my model works on GET and POST methods, but POST method doesn’t work in Glitch.

Glitch only uses this: HEAD, DELETE, GET, PUT.

Hmm, I don’t want to change hosting, I like Glitch, but what should I do in this situation?

oh did it go back to giving 405?

No, I’m getting a 505 error because the POST method doesn’t work on Glitch. Glitch only uses this: HEAD, DELETE, GET, PUT.

Is it possible how to solve this problem? I don’t want to change hosting :pensive:

I’m still getting HTTP 500, not 405 nor 505. is there something different you’re doing to get 405?

My mistake, typo. Error 500* This 500 error occurs because the POST method that my model uses does not work on Glitch. Any ideas how to solve this error?

Or will I have to change the hosting that supports the POST method? I don’t want to do this :frowning::persevere:

no, that was the description of HTTP 405 though

side note:

what site was that screenshot from? Glitch’s help site looks different, and it doesn’t mention POST not being supported.

https://help.glitch.com/kb/search/?q=HTTP%20405

I contacted Glitch support, I fixed the 405 error. But now the error is 500, they also told me that Glitch doesn’t support the POST method. But my model uses POST and GET methods. What do you think I need to do? Change hosting to run my model?

weird, they’re wrong about that. even the starter project uses POST. are you sure you didn’t mistakenly get in contact with some other service’s support?

don’t worry, the problem looks like it has a pretty simple solution. you’re just not able to see the problem right now. you’ll probably get it right away when you see it. I won’t spoil it for you. for now you just have to sort out your sources of information and filter out the bad actors dragging you in the wrong directions.

1 Like

I’m confused. I created a ticket on the site:

https://help.glitch.com/

There a support agent wrote me this, quote:

“It appears that the only methods that are allowed are: HEAD, DELETE, GET, PUT
Currently, the method being used by this requests is Post which is not allowed.”

I have been trying for a long time to find a solution to why my model does not work … and I can not find a solution. Yes, I see now a 500 error, the support agent says that the POST method does not work.
I uploaded the model.pkl file but it didn’t help… :expressionless::tired_face:

o dang, I believe you. I just tried logging in to the ticket system, and it does look like that. well I’m glad you asked here too :sweat_smile:

going back to the problem then, you’ve disregarded some things earlier in the thread due to this distraction with HTTP methods. let’s try to get you able to see the actual error and, importantly, error details so that you can start to convince yourself of what’s really going wrong. I’ll refer you back to this comment from earlier, on how to see the error yourself in your browser’s developer tools:

Hi - in that ticket, the Glitch Support agent was saying that the service you were making those calls to were not allowing POST - Glitch itself does not block usage of any endpoints.

Oh… the problem was caused by multiple factors. I was able to partially solve it. I created a new project, here is the updated link:

> https://nervous-spangle-sawfish.glitch.me/

What I fixed:

  1. My model was written in Python version 3.7, but Glitch hosting has Python version 2.7. I rewrote the code of my model and fixed related errors.
  2. It was important that the model.pkl file was recreated in version 2.7, so I recreated this file.

and then run the client.py file in the second terminal, I get the result.

This is a small progress in the launch.

But there is another problem…

When I navigate to my model’s address https://nervous-spangle-sawfish.glitch.me/ to check its functionality, I get a 405 error. :expressionless:

Here are the console logs in the browser:

POST https://nervous-spangle-sawfish.glitch.me/predict 405

Here are the logs in Glitch:

::ffff:127.0.0.1 - - [13/Apr/2023:20:39:36 +0000] “GET / HTTP/1.1” 304 - “https://glitch.com/” “Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 YaBrowser/23.3.1.895 Yowser/2.5 Safari/537.36”

::ffff:127.0.0.1 - - [13/Apr/2023:20:39:46 +0000] “POST /predict HTTP/1.1” 405 0 “https://nervous-spangle-sawfish.glitch.me/” “Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 YaBrowser/23.3.1.895 Yowser/2.5 Safari/537.36”

I almost solved it… but… I got confused… Could you please advise me on how to solve it? We are almost at the finish line… :sweat_smile:
Thank you!

I think you missed something when creating the new project, it looks like it’s running as a static site instead of as an app. So naturally there’s no “server” program handling the POST requests.

Nice fix on the pickle format thing btw. I think Glitch also has Python 3 installed, although you have to run it as python3 instead of python. Maybe try that out if it’s easier than maintaining a separate Python 2 copy of your project.

I started getting 405 error after adding requirements.txt file

Added the requirements.txt file and got back to the 405 error again :neutral_face:

Is it really possible to run this model on Glitch ? :persevere:

But when I restart the server, I get back to the 500 error. I’m completely confused now. :sob:

  1. How can I fix the 500 error?

have you been running the server manually in the terminal?

Yes, but the server starts itself when I enter the project. Now the error is 500, it changes every time, during the day I did not open the project and there was an error 405, and now again the error is 500, I opened the project an hour ago and started the server - 500 error. Is it related somehow?

that’s pretty weird. if you reproduce the 405 error, can you check what the Server header was in the response? when the project container is running, it should be something like Werkzeug. if it’s AmazonS3 or absent, then we should ask glitch support for help with a project startup problem.

The solution has been found. I just changed hosting and was able to run my app on pythonanywhere.com. :neutral_face:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.