Skip to content

Use requests library to validate the user #194

Open

Description

@delrius-euphoria

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

Activity

  1. delrius-euphoria commented on Jun 29, 2022

    @delrius-euphoria
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions