iyear / tdl

📥 A Telegram toolkit written in Golang
https://docs.iyear.me/tdl
GNU Affero General Public License v3.0
4.46k stars 442 forks source link

[Bug] 使用python调用异常 #712

Closed shaoyangx closed 2 months ago

shaoyangx commented 2 months ago

Describe the bug

我以前使用的自动下载的流程,但是很久未使用后,发现无法正常调用。(使用python的原因是bat无法便捷获取unix时间) 已在常规CMD进行测试,使用此命名空间可正常下载。 Python 3.12.3 tdl 0.17.3 在用以下代码调用tdl的时候,会显示未登录。 错误信息:

Error: callback:
    github.com/gotd/td/telegram.(*Client).Run.func3
        github.com/gotd/td@v0.105.0/telegram/connect.go:151
  - not authorized. please login first

To Reproduce

使用代码如下

import subprocess
import os
os.environ['TDL_PROXY']='socks5://127.0.0.1:10809'
os.environ['TDL_NS']='year'
original_path = os.environ.get('PATH')
os.environ['PATH'] = 'bin' + os.pathsep + original_path
subprocess.run(['tdl','chat', 'ls'])
os.system('pause')

Expected behavior

成功调用

Version

Version: 0.17.3 Commit: 6c382b8 Date: 2024-07-07T10:59:56Z

go1.21.11 windows/amd64

Which OS are you running tdl on?

Windows

Additional context

No response

iyear commented 2 months ago

not authorized. please login first

Please use tdl login to login before invoking other commands.

shaoyangx commented 2 months ago

not authorized. please login first

Please use tdl login to login before invoking other commands. But I've logged in to the namespace, and running the same code under bat works just fine.Python calls do not succeed

@ECHO OFF
set TDL_NS=year && set TDL_PROXY=socks5://127.0.0.1:10809
set path=bin;%path%
tdl chat ls

This command can correctly call the channel list

iyear commented 2 months ago

It's python code' error.

I guess this can't set environment variables.

os.environ['TDL_PROXY']='socks5://127.0.0.1:10809'
os.environ['TDL_NS']='year'
shaoyangx commented 2 months ago

There is nothing wrong with this environment variable. I used to be able to call it in Python, but one day it suddenly lapsed. In the middle of this, I didn't actively update the TDL version and Python. Maybe I should build an older version of Python for testing (maybe some of the environment configuration changes by accident?)

def config():
    global tdl
    #默认运行设置
    os.environ['TDL_PROXY']='socks5://127.0.0.1:10809'
    tdl = 'tdl.exe'

## Omitted……

def dl(): #下载模块
    for root, dirs, files in os.walk('json'):
        for f in files:
            Channel_name = os.path.splitext(f)
            if Channel_name[1] == '.json':
                ## 下载 -d指定下载目录 -f官方客户端导出的文件 -e黑名单 -i 白名单 --continue 不交互直接继续
                subprocess.run([tdl,'dl','-f','json/' + f,'-d','dl/' + Channel_name[0] ,'-e','webp,webm,png,jpg,tgs,apk','--skip-same','--continue','--reconnect-timeout','0'])
iyear commented 1 month ago

@shaoyangx The issue is most likely with the Python code, and I can't help you further.