Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use requests library to validate the user #194

Open
delrius-euphoria opened this issue Jun 29, 2022 · 1 comment
Open

Use requests library to validate the user #194

delrius-euphoria opened this issue Jun 29, 2022 · 1 comment

Comments

@delrius-euphoria
Copy link

delrius-euphoria commented Jun 29, 2022

def validate_github_profile(value):

Why not just use an additional step that uses request to check if the userprofile exists or not? Like:

>>> import requests
>>> req = requests.get('https://www.github.com/SomeUserThatDoesNotExistsHopefully')
>>> req.status_code
404
>>> req = requests.get('https://www.github.com/delrius-euphoria')
>>> req.status_code
200
@delrius-euphoria
Copy link
Author

delrius-euphoria commented Jun 29, 2022

A possible way is something like:

import requests

def validate_github_profile(value):
    """validate github profile"""

    pattern = r"^github.com\/[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*\/?$"
    if re.search(pattern, value) is None:
        raise ValidationError(
            _("%(value)s is not a valid GitHub profile."),
            params={"value": value},
        )
    status_code = requests.get(value).status_code
    if status_code == 404:
        raise ValidationError(
            _("%(value)s is not a valid GitHub profile."),
            params={"value": value},
        )      

Or something along the lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant