reluce / szurubooru-toolkit

Python package and script collection to manage your szurubooru image board.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: cannot unpack non-iterable NoneType object

bokerlol opened this issue · comments

Hello,

I'm receiving the following error when attempting to run any variation of the auto_tagger python script:

Z:\Misc\szurubooru\szurubooru-scripts-main>python3 auto_tagger.py 'id:126'
Could not process your query: 'total'.
Traceback (most recent call last):
  File "auto_tagger.py", line 129, in <module>
    main()
  File "auto_tagger.py", line 28, in main
    post_ids, total = api.get_post_ids(user_input.query)
TypeError: cannot unpack non-iterable NoneType object
{
    "szurubooru": {
        "url": "https://booru.mydomain.com/",
        "api_token": "my api token",
        "public": "False"
    },
    "auto_tagger": {
        "saucenao_api_key": "my api token",
        "hide_progress": "False",
        "local_tmp_path": "Z:/Misc/szurubooru/szurubooru-scripts-main/tmp",
        "use_saucenao": "True",
        "deepbooru_enabled": "False",
        "deepbooru_model": "Z:/Misc/szurubooru/szurubooru-scripts-main/misc/deepbooru/model-resnet_custom_v3.h5",
        "deepbooru_threshold": "0.7",
        "boorus": {
            "danbooru": {
                "user": "None",
                "api_key": "None"
            },
            "gelbooru": {
                "user": "None",
                "api_key": "None"
            },
            "konachan": {
                "user": "None",
                "password": "None"
            },
            "yandere": {
                "user": "None",
                "password": "None"
            },
            "pixiv": {
                "user": "None",
                "password": "None",
                "token": "None"
            }
        }
    },
    "upload_images": {
        "upload_dir": "I:/Images/Booru/posts",
        "hide_progress": "False",
        "cleanup": "False",
        "tags": ["tagme"]
    }
}

Hi, did you specify the api_token in your config.json file? If so, was it properly encoded as specified in the Readme?

I had a feeling that was the problem but I wasn't sure how to handle it. Maybe I'm overlooking something but when running the 'echo -n username:token | base64' it just spit out this:

'base64' is not recognized as an internal or external command,
operable program or batch file.

I feel like I'm missing something entirely on this part.

Also as a follow up, I did try to just encode the user:token using the base64 website and that didn't seem to get rid of the error either. Still feels like I'm missing something that I'm sure is very obvious lol.

Yeah, I'm reworking things in a private branch where Python does the encoding, still testing things out though (the base64 command is not compatible in a Windows shell).

In the meantime, you can start a Python shell and generate the token from there:

python3
>>> from base64 import b64encode
>>> b64encode("user:pass".encode("utf-8")).decode("ascii")

Does the token generated by that command work?

It did not, however, I managed to get the token to work (I think) when running it through base64encode.org in the proper formatting. Well, sort of. This command is still spitting out the same error as before: python3 auto_tagger.py 'date:today'

However, specifying a specific post ID provides a new error. Which is this:


Z:\Misc\szurubooru\szurubooru-scripts-main>python3 auto_tagger.py 126
Found 1 posts. Start tagging...
  0%|                                                     | 0/1 [00:00<?, ?it/s]Could not get result from SauceNAO with uploaded image: [Errno 2] No such file or directory: '/tmp/126_a2cfc930f4a5603e.jpg'
Traceback (most recent call last):
  File "auto_tagger.py", line 129, in <module>
    main()
  File "auto_tagger.py", line 65, in main
    tags, source, rating, limit_short, limit_long = saucenao.get_metadata(post)
  File "C:\Users\shrev\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\syncer.py", line 44, in run
    return asyncio.get_event_loop().run_until_complete(f(*args, **kwargs))
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File "Z:\Misc\szurubooru\szurubooru-scripts-main\classes\saucenao.py", line 64, in get_metadata
    if results.results:
AttributeError: 'NoneType' object has no attribute 'results'

Looking at it it seems that it isn't happy with the /tmp/ location. Even after I changed it to point to where all my posts are stored.

Should I create a new issue for this? Still unsure why the other command won't work but it isn't critical for it too..

So fetching from your szuru works now as it got your filename correctly.

I must admit that the script doesn't really verify the user input in the config file, I also haven't tested things out under "native" Windows as I'm using Ubuntu WSL.

How did you specify the local_tmp_path in the auto_tagger section in config.json?
Can you test with a path that is writable by your user? Something like C:/User/Foo/Desktop should probably work.

Same issue it seems.

Z:\Misc\szurubooru\szurubooru-scripts-main>python3 auto_tagger.py 120
Found 1 posts. Start tagging...
  0%|                                                     | 0/1 [00:00<?, ?it/s]Could not get result from SauceNAO with uploaded image: [Errno 2] No such file or directory: '/tmp/120_e9f99fac74a2e35f.jpg'
Traceback (most recent call last):
  File "auto_tagger.py", line 129, in <module>
    main()
  File "auto_tagger.py", line 65, in main
    tags, source, rating, limit_short, limit_long = saucenao.get_metadata(post)
  File "C:\Users\shrev\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\syncer.py", line 44, in run
    return asyncio.get_event_loop().run_until_complete(f(*args, **kwargs))
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File "Z:\Misc\szurubooru\szurubooru-scripts-main\classes\saucenao.py", line 64, in get_metadata
    if results.results:
AttributeError: 'NoneType' object has no attribute 'results'

This is my config file setup for the temp path:

"local_tmp_path": "C:/Users/shrev/Desktop/testing",

I noticed that no matter what I change the /tmp/ path to inside of the config, the error always spits out the folder /tmp/imagename.jpg. Is that intentional? It's almost as if it is completely disregarding what I put in the config file for my /tmp/ path.

Oh, the config_sample.json references the variable wrong. Instead of local_tmp_path it should be local_temp_path. As it's not finding the variable, it defaults to /tmp.

Can you test it with the updated variable/key name?

Bingo! Worked like a charm after fixing that!

Thank you!

Any clue why the 'python3 auto_tagger.py 'date:today'' isn't working? That one in particular would be very nice to have working as I plan on mass tagging daily as images are added.

Great to hear!

I think it would be best if we move that to a new issue. Can you create that issue with the error message?

In the meantime, I'm closing this one.