neocities / neocities-ruby

The Neocities Gem - A CLI and library for using the Neocities web site API.
https://neocities.org
52 stars 14 forks source link

(JSON::ParserError)/common.rb:156:in `parse': 765: unexpected token at '<html> <head><title>400 Bad Request</title> #21

Closed da2x closed 1 year ago

da2x commented 5 years ago

This worked a couple of hours ago, so I’m guessing that the API is temporary unavailable. The API isn’t listed on the status tracker so I don’t really know, though.

At any rate, the client should handle this error condition better.

$ neocities version
0.0.13

$ neocities info kyledrake
Traceback (most recent call last):
    8: from /usr/local/bin/neocities:23:in `<main>'
    7: from /usr/local/bin/neocities:23:in `load'
    6: from /usr/local/share/gems/gems/neocities-0.0.13/bin/neocities:4:in `<top (required)>'
    5: from /usr/local/share/gems/gems/neocities-0.0.13/lib/neocities/cli.rb:79:in `run'
    4: from /usr/local/share/gems/gems/neocities-0.0.13/lib/neocities/cli.rb:107:in `info'
    3: from /usr/local/share/gems/gems/neocities-0.0.13/lib/neocities/client.rb:70:in `info'
    2: from /usr/local/share/gems/gems/neocities-0.0.13/lib/neocities/client.rb:77:in `get'
    1: from /usr/share/ruby/json/common.rb:156:in `parse'
 (JSON::ParserError)/common.rb:156:in `parse': 765: unexpected token at '<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>openresty</center>
</body>
</html>
'

$ neocities push directory/
Uploading contact.html ... Traceback (most recent call last):
    13: from /usr/local/bin/neocities:23:in `<main>'
    12: from /usr/local/bin/neocities:23:in `load'
    11: from /usr/local/share/gems/gems/neocities-0.0.13/bin/neocities:4:in `<top (required)>'
    10: from /usr/local/share/gems/gems/neocities-0.0.13/lib/neocities/cli.rb:79:in `run'
     9: from /usr/local/share/gems/gems/neocities-0.0.13/lib/neocities/cli.rb:185:in `push'
     8: from /usr/local/share/gems/gems/neocities-0.0.13/lib/neocities/cli.rb:185:in `chdir'
     7: from /usr/local/share/gems/gems/neocities-0.0.13/lib/neocities/cli.rb:215:in `block in push'
     6: from /usr/local/share/gems/gems/neocities-0.0.13/lib/neocities/cli.rb:215:in `each'
     5: from /usr/local/share/gems/gems/neocities-0.0.13/lib/neocities/cli.rb:218:in `block (2 levels) in push'
     4: from /usr/local/share/gems/gems/neocities-0.0.13/lib/neocities/client.rb:54:in `upload'
     3: from /usr/local/share/gems/gems/neocities-0.0.13/lib/neocities/client.rb:42:in `upload_hash'
     2: from /usr/local/share/gems/gems/neocities-0.0.13/lib/neocities/client.rb:83:in `post'
     1: from /usr/share/ruby/json/common.rb:156:in `parse'
 (JSON::ParserError)/common.rb:156:in `parse': 765: unexpected token at '<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>openresty</center>
</body>
</html>
'
da2x commented 5 years ago

This issue was originally reported against 0.0.9 but I’ve updated and reconfirmed on 0.0.13.

bobemoe commented 4 years ago

Did you ever figure this out? Getting similar:

$ neocities push public
/usr/local/lib/ruby/2.7.0/json/common.rb:156:in `parse': 783: unexpected token at '<html>\r (JSON::ParserError)
<head><title>400 Bad Request</title></head>\r
<body>\r
<center><h1>400 Bad Request</h1></center>\r
<hr><center>openresty</center>\r
</body>\r
</html>\r
'
    from /usr/local/lib/ruby/2.7.0/json/common.rb:156:in `parse'
    from /usr/local/bundle/gems/neocities-0.0.15/lib/neocities/client.rb:87:in `post'
    from /usr/local/bundle/gems/neocities-0.0.15/lib/neocities/client.rb:42:in `upload_hash'
    from /usr/local/bundle/gems/neocities-0.0.15/lib/neocities/client.rb:54:in `upload'
    from /usr/local/bundle/gems/neocities-0.0.15/lib/neocities/cli.rb:225:in `block (2 levels) in push'
    from /usr/local/bundle/gems/neocities-0.0.15/lib/neocities/cli.rb:222:in `each'
    from /usr/local/bundle/gems/neocities-0.0.15/lib/neocities/cli.rb:222:in `block in push'
    from /usr/local/bundle/gems/neocities-0.0.15/lib/neocities/cli.rb:191:in `chdir'
    from /usr/local/bundle/gems/neocities-0.0.15/lib/neocities/cli.rb:191:in `push'
    from /usr/local/bundle/gems/neocities-0.0.15/lib/neocities/cli.rb:79:in `run'
    from /usr/local/bundle/gems/neocities-0.0.15/bin/neocities:4:in `<top (required)>'
    from /usr/local/bundle/bin/neocities:23:in `load'
    from /usr/local/bundle/bin/neocities:23:in `<main>'
bobemoe commented 4 years ago

For me this was because of a newline at the end of the API key config file. Use nano -L or echo -n to prevent the newline.