使用 Pyinstaller 将 PRAW python 文件转换为 exe 时出现“AttributeError: '_NotSet' object has no attribute 'lower'”

2023-12-27

正如标题所说。

当我执行转换后的 python 文件(.exe)时,我得到以下输出:

Traceback (most recent call last):
  File "background.py", line 10, in <module>
  File "site-packages\praw\reddit.py", line 129, in __init__
  File "site-packages\praw\config.py", line 72, in __init__
  File "site-packages\praw\config.py", line 98, in _initialize_attributes
  File "site-packages\praw\config.py", line 31, in _config_boolean
AttributeError: '_NotSet' object has no attribute 'lower'
[1692] Failed to execute script background

我没有使用 praw.ini 文件,而是对登录值进行硬编码,如下所示:

import praw
import praw.models
import urllib.request
from random import randint
from os import getcwd
import ctypes

r = praw.Reddit(client_id='client',
                     client_secret='secret',
                     user_agent='user')
sub = r.subreddit('earthporn')
choose = []
for i in sub.hot(limit=20):
    a = str(i.url)
    if "i.redd" in a or "i.imgur" in a:
        choose.append(i.url)
x = choose[randint(0,len(choose)-1)]
resource = urllib.request.urlopen(x)
output = open("daily_image.jpg","wb")
output.write(resource.read())
output.close()


direc = getcwd() + "\\daily_image.jpg"
ctypes.windll.user32.SystemParametersInfoW(20, 0, direc , 0)

上面的文件仅在 python 中有效,但在转换为 exe 时无效。 (显然已经设置了客户端、秘密和用户 ID,请随意窃取 idrc)

非常感谢任何帮助!


我遇到了这个错误,发现要解决它,您需要有一份praw.ini在运行可执行文件的目录中(your_app.exe) 从。您可以找到您的praw.ini在你安装的\praw目录。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Pyinstaller 将 PRAW python 文件转换为 exe 时出现“AttributeError: '_NotSet' object has no attribute 'lower'” 的相关文章

随机推荐