QPython3中的FileNotFoundError

2024-04-20 11:53:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经在桌面上运行并测试了python3.7,并试图在Android上运行。我已经安装了QPython3,并使用Pip控制台安装了Requests和BeautifulSoup4,但是遇到了一个新的错误,我不知道该如何解决,因为我不知道为什么它没有看到配置.json在剧本旁边。你知道吗

我还没有尝试过太多,因为我不知道可能导致这个问题的具体原因。我在2015年读到qpython的一些问题,有绝对文件目录,但没有立即的,文件路径看起来是绝对的。你知道吗

我使用的代码如下: https://gist.github.com/Treeki/006a30d2f6e07213aa51

这正是我通过python徽标运行脚本后从控制台得到的结果。你知道吗

脚本和配置都位于Qpython下的Scripts3文件夹中,该文件夹位于可通过手机存储器上的USB访问的目录中。你知道吗

/data/user/0/org.qpython.qpy3/files/bin/qpython3-android5.sh  /storage/emulated/0/qpython/scripts3/fa_notifier.py  && exit
ripts3/fa_notifier.py  && exit             <
Configuration file not specified, defaulting to ./config.json
Traceback (most recent call last):
  File "/storage/emulated/0/qpython/scripts3/fa_notifier.py", line 453, in <module>
    main()
  File "/storage/emulated/0/qpython/scripts3/fa_notifier.py", line 438, in main
    with open(config_path, 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'config.json'
1|u0_a295@tbltecan:/ $

编辑: 我找到了它指向的地方配置.json假设

将第一个if语句中的config\u path更改为绝对地址,而不是'/配置.json'

这消除了这个错误,但现在它只是进入第一轮投票,然后说投票失败,没有具体的错误,所以我不确定,如果它有问题的凭据或cookies,因为它在android上?你知道吗

    # Obtain and read the configuration file
    if len(sys.argv) <= 1:
        config_path = '/storage/emulated/0/qpython/scripts3/config.json'
        print('Configuration file not specified, defaulting to ./config.json')
    elif len(sys.argv) == 2:
        config_path = sys.argv[1]
        print('Reading configuration from %s' % config_path)
    else:
        print('Usage: python %s [config.json]' % sys.argv[0])
        return

    with open(config_path, 'r') as f:
        raw_config = f.read()

    try:
        config = json.loads(raw_config)
    except ValueError:
        print('JSON parsing error while reading configuration!')
        raise

    # Work on it!
    n = Notifier(config)
    n.execute()```  

Tags: pathpyconfigjson错误sysstoragenotifier