Skip to content

Commit

Permalink
Updated Check URL
Browse files Browse the repository at this point in the history
  • Loading branch information
dyohan9 committed Oct 8, 2019
1 parent 1a5290d commit 943ff68
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ gevent = "*"
packaging = "*"
django-environ = "*"
boto3 = "*"
validators = "*"

[dev-packages]
"flake8" = "*"
Expand Down
16 changes: 1 addition & 15 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions bothub/api/v2/nlp/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import base64
import json
import requests
import validators

from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.shortcuts import get_object_or_404
from django.core.validators import URLValidator
from django.core.exceptions import ValidationError

from rest_framework import mixins
from rest_framework import exceptions
Expand Down Expand Up @@ -420,7 +421,15 @@ def retrieve(self, request, *args, **kwargs):
check_auth(request)
update = self.get_object()

if validators.url(str(update.bot_data).lower()):
validator = URLValidator()

try:
validator(str(update.bot_data))
url_valid = True
except ValidationError:
url_valid = False

if url_valid:
try:
download = requests.get(update.bot_data)
bot_data = base64.b64encode(download.content)
Expand Down

0 comments on commit 943ff68

Please sign in to comment.