curl.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:telegram-yt_mp3-bot 作者: Javinator9889 项目源码 文件源码
def descarga(full_name):
    url = 'https://file.io/?expires=1w'
    files = {'file': open(full_name,'rb')}
    print("\n\tSubiendo archivo a 'file.io'")
    link = None
    n=0
    while link==None:                                                    # For ensuring that the file is uploaded correctly
        response = requests.post(url, files=files)
        test = response.text
        print("JSON recibido: ",test)
        decoded = unidecode(test)                                        # It's needed to decode text for avoiding 'bytes' problems (b'<meta...)
        print("JSON decodificado: ",decoded)
        if '<html>' in decoded:                                          # When upload fails, 'file.io' sends a message with <html> header.
            print("\n\tFallo al subir el archivo. Reintentando... #",n)  # If it's detected, assings 'link = None' and then 'while' loop restars
            link = None
            n=n+1                                                        # Little counter
        else:
            json_data = json.loads(decoded)
            link = json_data['link']
            print("\n\nEnlace de descarga directa: ",link)
    return link
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号