Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"AttributeError: '_NotSet' object has no attribute 'lower'" when a PRAW python file is converted to an exe using Pyinstaller

As the title says.

When I execute the converted python file (the .exe) I get the following output:

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

I did not use a praw.ini file, instead hardcoding the values for the logon as such:

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)

The above file works in just python but not when converted to an exe. (obviously with the client,secret and user id's set, feel free to steal it idrc)

Any help is really appreciated!

like image 571
Recessive Avatar asked Dec 23 '22 08:12

Recessive


2 Answers

I had this error and found that to resolve it you need to have a copy of the praw.ini in the directory where you a running the executable (your_app.exe) from. You can find your praw.ini in your installed \praw directory.

like image 80
Callum Pearce Avatar answered Apr 27 '23 04:04

Callum Pearce


Right.

So, pyinstaller isn't a perfect .py to .exe converter, so some things get lost in translation.

I first commented out all updating in praw as this caused a crash in the .exe created by pyinstaller (note everything I did here caused errors in the .exe but never in the .py).

I then had to manually set some variables along the way because they weren't set when they were called in the .exe version. Either threading is used in PRAW and in the .exe version it can't keep up, or there's some seriously weird shit going on.

Yeh so I basically just modified code all throughout praw so this thing would run. If anyone comes across this issue like me and can't find the answer anywhere (because trust me I scoured planet Earth and it's no where to be found) message me and I can send you my praw version.

May god forbid you get this error

like image 28
Recessive Avatar answered Apr 27 '23 03:04

Recessive