M
M
Maxim2017-01-31 12:34:55
Python
Maxim, 2017-01-31 12:34:55

Getting an error when uploading a photo using urlilib?

Why do I get an error when uploading photos with wget? I have been using it for a long time and nothing like this happened.
fb5d20fbe04c470584e8f623439825a7.png
What is the reason for this and how to solve the problem?
PS opens without problems
https://cdn-images-1.medium.com/fit/c/200/200/1*dm... "

def download(url, path, token):
    if not os.path.exists(path):
        os.makedirs(path)
    try:
        user = UserProfile.objects.get(token=token)
        name = wget.detect_filename(url)
        # file_extension = os.path.splitext(name)[1]
        file_extension =check_extension(name)
        file_path = path  + '/' + str(user.id) +'_' + '0' + file_extension
        if os.path.exists(file_path):
            os.remove(file_path)
        filename = wget.download(url, file_path)
        file_http = site_url + 'static/' + str(user.id) + '/' + str(user.id) + '_' + '0' + file_extension
        return file_http
    except Exception as e:
        return False

self.user.photo = download(resp.get('imageUrl'), upload_dir + str(self.user.id), self.user.token)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad_Fedorenko, 2017-01-31
@Vlad_Fedorenko

Try adding headers, user agent first

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question