Search code examples
pythonpython-3.xurllibgifanimated-gif

I can't save an Gif from a URL with python


I get a link from Tenor and I want to get the gif downloaded. I use this code (Python 3.6):

from urllib import request
request.urlretrieve('https://media.tenor.com/images/0ba0cfa366db09213ab0352834b53bdf/tenor.gif', 'myfile.gif')

But I get this error form the console:

request.urlretrieve('https://media.tenor.com/images/0ba0cfa366db09213ab0352834b53bdf/tenor.gif', 'C:\Users\Javier Jiménez\Documents\Javi\BOT\myfile.gif')
                                                                                                ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

I hope you could help me. Thanks!!


Solution

  • Can you set utf-8 encoding before this code ? it's working fine for me.

    # -*- coding: utf-8 -*-