Forums

Getting 401 while pinging my website.

Hi, I've made a Django website and I am using a task to ping my website so I know it's up. The task just requests a page with a key so I know it's coming from me, but even though it worked on localhost with Debug on, it doesn't work when I use the script from my account.

I tried using requests like this:

import requests

url = "https://www.mypage.com/"
req = requests.get(url)

This returns a 401 "Unauthorized"

I also tried with selenium and I got the same result.

This is how the view looks on the server side:

@csrf_exempt
def pinghere(request, key):
    print("My key is", key)
    # Do stuff
    return JsonResponse({"stuff": "here"})

and this is the path to the view:

path("something/something/something/<str:key>", pinghere)

I don't think there are problems with the views since it worked on localhost, but that was with DEBUG=True.

I didn't want to use django rest framework since I don't have that much experience with it, but if someone can suggest an answer with it, I would obviously use it.

Maybe write to support@pythonanywhere with unobfuscated URLs and paths, so we can see what you are doing.