Click here to Skip to main content
15,745,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to make a program that checks username availability on I'm trying to do this by entering a profile URL letting the code check whether the site gives a 200- or a 404 status code, with 404 being a Taken username and 200 an Available username.

If an username is taken on the website it will give a 200-Status code, while if the username does not yet exist it will give a 404 page.

So first of all here's the code
import pyfiglet
import datetime
import urllib.request

ascii_banner = pyfiglet.figlet_format("Made  By  Gxzs!!")
print("Press ENTER to begin checking")


if (urllib.request.urlopen("").getcode()) == 200:
    print ("TAKEN")
if (urllib.request.urlopen("").getcode()) == 404:
    print ("AVAILABLE!")

I used an available username to test the code:

The output of the code is TAKEN, which means the page gave a 200-Status code according to the code. But if you look up the link of the tested username it gives a 404-Status code as the username is unavailable.

What I have tried:

I have tried checking other links with available usernames, but all gave a 200 status code and had output TAKEN
Updated 6-May-21 13:13pm

1 solution

You're getting a legit page from that URL with a dialog box to register. A valid page means a response code of 200 in HTTP.

404 means "Page not found" in HTTP, the URL didn't return any valid page from the server.
Share this answer
gxzs. 6-May-21 19:19pm    
I understand that 200 is a valid page and thus for my code should be an unavailable username as the username already exists.

I also understand that 404 is a page that doesn't exist, because I used that for if page gives status code 404 then print available.

The problem is that it always says "TAKEN", meaning it gave a 202 status code. But it should have given a 404 status code as the page does not exist.

For example if you look up (the URL I used in my code to test the code) the page gives a statuscode 404, while the code gives a statuscode 200
Dave Kreskowiak 6-May-21 19:23pm    
That's not your code. That return code is coming from the server! There's nothing you can do to change that.

I tried that URL. It returns a valid page with a 200.

gxzs. 6-May-21 19:52pm    
Oh that explains a lot, thank you. Is there any way to make it print (“AVAILABLE”) if an username exists (like and print (“TAKEN”) if an username is taken (like
Dave Kreskowiak 6-May-21 20:58pm    
How about ask Ubisoft if there's an API you can use.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900