#1 error during login check when attempting to push

Затворени
отворен преди 5 години от renken · 7 коментара
renken коментира преди 5 години

I am having issues trying to push my (first) changes to the weblog to neocities, this occurs right after I get prompted to enter my neocities password. here's the scenario

$ ./push
You are about to upload your website (public_html/*) to Neocities!
Password for renken.neocities.org:
Checking credentials...
Traceback (most recent call last):
  File "neocities_files.py", line 98, in <module>
    login_result = check_login()
  File "neocities_files.py", line 16, in check_login
    files = json.loads(raw_json)
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
---------------------------------------------------------
WARNING: Existing files on Neocities will be overwritten.
WARNING: Neocities files that don't exist in your public_html/ directory will be deleted! Download your whole website and copy the files into the public_html directory!
Please confirm: Are you sure you want to continue? (y/n)
y
Uploading files...
./push: line 48: files.upload.list: No such file or directory
Removing files...
./push: line 48: files.delete.list: No such file or directory
--------------------------------------------
0 file(s) successfully uploaded!
0 file(s) deleted.
OK.

I use keepassxc and have to copy-paste my password, I typed a wrong password and it returned the following so this should be a bug

$ ./push
You are about to upload your website (public_html/*) to Neocities!
Password for renken.neocities.org:
Checking credentials...
Invalid username or password. Please check your credentials and try again. To change your username, edit the first line of the "nci.conf" file.

lovely tool, thanks for providing it

I am having issues trying to push my (first) changes to the weblog to neocities, this occurs right after I get prompted to enter my neocities password. here's the scenario ```sh $ ./push You are about to upload your website (public_html/*) to Neocities! Password for renken.neocities.org: Checking credentials... Traceback (most recent call last): File "neocities_files.py", line 98, in <module> login_result = check_login() File "neocities_files.py", line 16, in check_login files = json.loads(raw_json) File "/usr/lib/python3.7/json/__init__.py", line 348, in loads return _default_decoder.decode(s) File "/usr/lib/python3.7/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) --------------------------------------------------------- WARNING: Existing files on Neocities will be overwritten. WARNING: Neocities files that don't exist in your public_html/ directory will be deleted! Download your whole website and copy the files into the public_html directory! Please confirm: Are you sure you want to continue? (y/n) y Uploading files... ./push: line 48: files.upload.list: No such file or directory Removing files... ./push: line 48: files.delete.list: No such file or directory -------------------------------------------- 0 file(s) successfully uploaded! 0 file(s) deleted. OK. ``` I use keepassxc and have to copy-paste my password, I typed a wrong password and it returned the following so this should be a bug ```sh $ ./push You are about to upload your website (public_html/*) to Neocities! Password for renken.neocities.org: Checking credentials... Invalid username or password. Please check your credentials and try again. To change your username, edit the first line of the "nci.conf" file. ``` lovely tool, thanks for providing it
renken коментира преди 5 години
Участник

after a quick check, apparently it's failing because the file files.json is empty and therefore python's json decoder failure. based on the code, you assume that success implies returning

{
   success: "true"
}

or something similar, where in fact it's returning nothing?

after a quick check, apparently it's failing because the file `files.json` is empty and therefore python's json decoder failure. based on the code, you assume that success implies returning ```json { success: "true" } ``` or something similar, where in fact it's returning nothing?
nokoru коментира преди 5 години
Притежател

is your "files.json" file empty or it's just an assumption?

if "files.json" isn't empty, the error might be being caused by the open("files.json").read() function which is returning either an invalid json format or invalid character encoding.

let me figure out how can I fix this issue.

sorry for the inconvenience :c

is your "files.json" file empty or it's just an assumption? if "files.json" isn't empty, the error might be being caused by the ```open("files.json").read()``` function which is returning either an invalid json format or invalid character encoding. let me figure out how can I fix this issue. sorry for the inconvenience :c
nokoru посочи тази задача от ревизия преди 5 години
renken коментира преди 5 години
Участник

files.json is empty, not an assumption.

the problem is in line 16 files = json.loads(raw_json) because it tries to read an empty file which is of invalid json format.

thank you!

`files.json` is empty, not an assumption. the problem is in line 16 `files = json.loads(raw_json)` because it tries to read an empty file which is of invalid json format. thank you!
renken коментира преди 5 години
Участник

I pulled the last changes and here's the output

$ ./push 
You are about to upload your website (public_html/*) to Neocities!
Password for renken.neocities.org:
Checking credentials...
  File "neocities_files.py", line 18
    except ValueError as err:
                            ^
TabError: inconsistent use of tabs and spaces in indentation
---------------------------------------------------------
WARNING: Existing files on Neocities will be overwritten.
WARNING: Neocities files that don't exist in your public_html/ directory will be deleted! Download your whole website and copy the files into the public_html directory!
Please confirm: Are you sure you want to continue? (y/n)

I fixed the issue by properly replacing the spaces indentation for the newly added lines with tabs. you can do the opposite if you're a fan of spaces, here's the other output

$ ./push
You are about to upload your website (public_html/*) to Neocities!
Password for renken.neocities.org:
Checking credentials...
Invalid JSON format.
You are experiencing a known issue. Please report it here https://notabug.org/nokoru/nci/issues/1
Sorry! :c
-------------------------------------------------------
Details:
raw_json = 
Traceback (most recent call last):
  File "neocities_files.py", line 17, in check_login
    files = json.loads(raw_json)
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "neocities_files.py", line 112, in <module>
    login_result = check_login()
  File "neocities_files.py", line 25, in check_login
    print("typeof raw_json = " + type(raw_json))
TypeError: can only concatenate str (not "type") to str
---------------------------------------------------------

I added a small workaround it at line 9, but also lead me to another error

if os.stat("files.json").st_size == 0:
    return 0

and the output was the following

$ ./push                 
You are about to upload your website (public_html/*) to Neocities!
Password for renken.neocities.org:
Checking credentials...
Successfully logged in!
Comparing files...
Traceback (most recent call last):
  File "neocities_files.py", line 125, in <module>
    init_comparison()
  File "neocities_files.py", line 52, in init_comparison
    remote_files = json.loads(open("files.json").read())["files"]
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
---------------------------------------------------------

you seem to to rely heavily on files.json and expect success and the files already existing in neocities, possibly double check what neocities API will return?

I ran curl -s "https://$username:$password@neocities.org/api/list" >> files.json and it did indeed return an empty file and I found the reason why. my password is randomly generated and made the URL invalid because I use characters other than letters and numbers, I tested it on my browser as well firefox and couldn't properly handle it. I suggest you switch to using API keys instead to both guarantee that one's password doesn't get to the wrong hands and to avoid such quirks trying to satisfy both passwords and the way URLs work. temporary solution is to parse the link in python and check if it's a valid URL, if not quit and tell the user that their password is not supported and should wait for the API key version (that's if you feel like adding support for it)

amazing tool, thanks for the help!

I pulled the last changes and here's the output ```sh $ ./push You are about to upload your website (public_html/*) to Neocities! Password for renken.neocities.org: Checking credentials... File "neocities_files.py", line 18 except ValueError as err: ^ TabError: inconsistent use of tabs and spaces in indentation --------------------------------------------------------- WARNING: Existing files on Neocities will be overwritten. WARNING: Neocities files that don't exist in your public_html/ directory will be deleted! Download your whole website and copy the files into the public_html directory! Please confirm: Are you sure you want to continue? (y/n) ``` I fixed the issue by properly replacing the spaces indentation for the newly added lines with tabs. you can do the opposite if you're a fan of spaces, here's the other output ```sh $ ./push You are about to upload your website (public_html/*) to Neocities! Password for renken.neocities.org: Checking credentials... Invalid JSON format. You are experiencing a known issue. Please report it here https://notabug.org/nokoru/nci/issues/1 Sorry! :c ------------------------------------------------------- Details: raw_json = Traceback (most recent call last): File "neocities_files.py", line 17, in check_login files = json.loads(raw_json) File "/usr/lib/python3.7/json/__init__.py", line 348, in loads return _default_decoder.decode(s) File "/usr/lib/python3.7/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "neocities_files.py", line 112, in <module> login_result = check_login() File "neocities_files.py", line 25, in check_login print("typeof raw_json = " + type(raw_json)) TypeError: can only concatenate str (not "type") to str --------------------------------------------------------- ``` I added a small workaround it at line 9, but also lead me to another error ```py if os.stat("files.json").st_size == 0: return 0 ``` and the output was the following ```sh $ ./push You are about to upload your website (public_html/*) to Neocities! Password for renken.neocities.org: Checking credentials... Successfully logged in! Comparing files... Traceback (most recent call last): File "neocities_files.py", line 125, in <module> init_comparison() File "neocities_files.py", line 52, in init_comparison remote_files = json.loads(open("files.json").read())["files"] File "/usr/lib/python3.7/json/__init__.py", line 348, in loads return _default_decoder.decode(s) File "/usr/lib/python3.7/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) --------------------------------------------------------- ``` you seem to to rely heavily on `files.json` and expect `success` and the files already existing in neocities, possibly double check what neocities API will return? I ran `curl -s "https://$username:$password@neocities.org/api/list" >> files.json` and it did indeed return an empty file and I found the reason why. my password is randomly generated and made the URL invalid because I use characters other than letters and numbers, I tested it on my browser as well firefox and couldn't properly handle it. I suggest you switch to using API keys instead to both guarantee that one's password doesn't get to the wrong hands and to avoid such quirks trying to satisfy both passwords and the way URLs work. temporary solution is to parse the link in python and check if it's a valid URL, if not quit and tell the user that their password is not supported and should wait for the API key version (that's if you feel like adding support for it) amazing tool, thanks for the help!
renken коментира преди 5 години
Участник

oops, I skimmed through their wiki and didn't notice that you need to provide the username:password regardless -even if you want to retrieve a key- which means that people have to change their passwords to satisfy a successful login.

fix it by changing curl -s "https://$username:$password@neocities.org/api/list" >> files.json to curl -s -u '$username:$password' "https://neocities.org/api/list" >> files.json

however because my password has ! in it, the shell treated it as a special event in and returned bash/zsh: event not found: -characters after the !- which as far as I know is because of the auto-completion expansion. to fix this I had to escape the ! by inserting \ before it.

two ways to fix this is either by finding a way to escape the password in shell (I can't help with that sorry, not experienced in shell) and the other solution is rewriting it in python which should be as simple as doing it in shell.

it depends on your language preference

oops, I skimmed through their wiki and didn't notice that you need to provide the `username:password` regardless -even if you want to retrieve a key- which means that people have to change their passwords to satisfy a successful login. fix it by changing `curl -s "https://$username:$password@neocities.org/api/list" >> files.json` to `curl -s -u '$username:$password' "https://neocities.org/api/list" >> files.json` however because my password has `!` in it, the shell treated it as a special event in and returned `bash/zsh: event not found: -characters after the !-` which as far as I know is because of the auto-completion expansion. to fix this I had to escape the `!` by inserting `\` before it. two ways to fix this is either by finding a way to escape the password in shell (I can't help with that sorry, not experienced in shell) and the other solution is rewriting it in python which should be as simple as doing it in shell. it depends on your language preference
nokoru посочи тази задача от ревизия преди 5 години
nokoru посочи тази задача от ревизия преди 5 години
nokoru коментира преди 5 години
Притежател

Okay, I just updated the script. After fixing annoying bugs like the indentation error (I don't know why tabs were replaced by spaces), I finally pushed a temporary solution:

If user has a non-supported password (it contains '!', '@', etc), then the program will tell the user to use its API key instead (it's not necessary to use curl to generate a key, you can do it here: https://neocities.org/settings/<your_username>#api_key)

Once you generated an API key, then you can use it to push your website/blog, run ./push -k instead of ./push, and the script will prompt you for your key and no password will be required.

I tried to upload and delete some images and it worked for me. Please let me know if you're still having issues with this tool.

I'll be trying to escape non-supported password characters, but I think this is enough for now.

Thank you for reporting this issue!

Okay, I just updated the script. After fixing annoying bugs like the indentation error (I don't know why tabs were replaced by spaces), I finally pushed a temporary solution: If user has a non-supported password (it contains '!', '@', etc), then the program will tell the user to use its API key instead (it's not necessary to use ```curl``` to generate a key, you can do it here: https://neocities.org/settings/&lt;your_username&gt;#api_key) Once you generated an API key, then you can use it to push your website/blog, run ```./push -k``` instead of ```./push```, and the script will prompt you for your key and no password will be required. I tried to upload and delete some images and it worked for me. Please let me know if you're still having issues with this tool. I'll be trying to escape non-supported password characters, but I think this is enough for now. Thank you for reporting this issue!
renken коментира преди 5 години
Участник

it's working fine for me as well, this issue can be closed.

it's working fine for me as well, this issue can be closed.
Впишете се за да се присъедините към разговора.
Няма етап
Няма изпълнител
2 участника
Зареждане...
Отказ
Запис
Все още няма съдържание.