Forums

What do I change my jQuery AJAX post URL to when moving local files to pythonanywhere?

I am very new to flask and am not really sure what I'm doing. I have a python web app that works on my localhost but I cant get it to work in pythonanywhere. I think it might have to do with my AJAX url, I've tried a bunch but I'm not sure what is the correct format. "http/username.pythonanywhere.com/ebaycode" is what I tried last.

$.ajax({
        url: 'http://127.0.0.1:5000/ebaycode/',
        data: {'product': product, 'sold': sold, 'cond': cond},
        method: 'POST'

That's part of my index.html, the top of my flask app looks like this:

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/ebaycode', methods=['POST'])
def ebaycode():
    prod = str(request.form.get('product', 0))
    sold = str(request.form.get('sold', 0))
    cond = str(request.form.get('cond', 0))

I think if you put the url as /ebaycode/, that should work for both localhost and PythonAnywhere.

If you are still seeing problems, check your browser developer toolbar's network tab to dig into what is happening with that post.

Also check your webapp error logs on PythonAnywhere.

https://imgur.com/a/Qq3hBOc - error message

Ok I changed the url to /ebaycode/ and inspected the server stuff, I get an internal server error that shows up on http:// mander39.pythonanywhere.com/ebaycode/

In my error log I get this error:

urllib.error.URLError: <urlopen error Tunnel connection failed: 403 Forbidden>

I import urllib.request for this (from urllib.request import urlopen) could that be the issue?

I fixed it by buying a premium account, it just wasnt letting me connect to another website. Thanks for the help!

ah ok, thanks for letting us know!