You are not logged in.
Hello all,
I used to have the following script working (stopped working about 2/3 weeks ago, but didn't realised) - it connect to pyLoad and extract a json response whether or not pyLoad was actually downloading or not.
#!/bin/bash
set -e
set -x
SessionID=$(curl -s "http://192.168.1.90:8000/api/login" -g -H "Host: 192.168.1.90:8000" -H "Content-Type: application/x-www-form-urlencoded" --data "username=user&password=password" | jq -r)
SessionStatus=$(curl -s "http://192.168.1.90:8000/api/statusServer" -g -H "Host: 192.168.1.90" -H "Content-Type: application/x-www-form-urlencoded" --data "session=$SessionID" | jq -r '.active')
if [ $SessionStatus -eq 1 ]
then
exit 0
else
exit 1
fi
That's the JSON available on 'http://192.168.1.90:8000/api/statusServer':
{"pause": false, "active": 0, "queue": 4, "total": 5, "speed": 0, "download": true, "reconnect": false, "captcha": false}
And that's the answer I get, with the "null" return instead of the "0" or number of active download.
$ sh autosuspend_script/pyload_autosuspend.sh
++ curl -s http://192.168.1.90:8000/api/login -g -H 'Host: 192.168.1.90:8000' -H 'Content-Type: application/x-www-form-urlencoded' --data 'username=user&password=password'
++ jq -r
+ SessionID='{
"_permanent": true,
"authenticated": true,
"id": 1,
"name": "pyload",
"role": 0,
"perms": 0,
"template": "default",
"_flashes": [
[
"message",
"Logged in successfully"
]
]
}'
++ curl -s http://192.168.1.90:8000/api/statusServer -g -H 'Host: 192.168.1.90' -H 'Content-Type: application/x-www-form-urlencoded' --data 'session={
"_permanent": true,
"authenticated": true,
"id": 1,
"name": "pyload",
"role": 0,
"perms": 0,
"template": "default",
"_flashes": [
[
"message",
"Logged in successfully"
]
]
}'
++ jq -r .active
+ SessionStatus=null
+ '[' null -eq 1 ']'
autosuspend_script/pyload_autosuspend.sh: line 10: [: null: integer expression expected
+ exit 1
Thank you for taking the time to read my topic, and for your assistance.
Offline
Remove the pipe to 'jq -r ".active"' and post the actual output from that curl command in the context of that script.
Last edited by Trilby (2023-06-08 19:16:01)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thank you for your help and assistance, please see below the output of the script without the 'jq'
$ sh autosuspend_script/pyload_autosuspend.s
h
++ curl -s http://192.168.1.90:8000/api/login -g -H 'Host: 192.
168.1.90:8000' -H 'Content-Type: application/x-www-form-urlenco
ded' --data 'username=user&password=password'
+ SessionID='{"_permanent": true, "authenticated": true, "id":
1, "name": "pyload", "role": 0, "perms": 0, "template": "defaul
t", "_flashes": [["message", "Logged in successfully"]]}'
++ curl -s http://192.168.1.90:8000/api/statusServer -g -H 'Hos
t: 192.168.1.90' -H 'Content-Type: application/x-www-form-urlen
coded' --data 'session={"_permanent": true, "authenticated": tr
ue, "id": 1, "name": "pyload", "role": 0, "perms": 0, "template
": "default", "_flashes": [["message", "Logged in successfully"
]]}'
+ SessionStatus='{"error": "Unauthorized"}'
+ '[' '{"error":' '"Unauthorized"}' -eq 1 ']'
autosuspend_script/pyload_autosuspend.sh: line 10: [: too many
arguments
+ exit 1
Offline
It's also actually in the original post.
Now take a close look at it.
Does it look like "{"pause": false, "active": 0, "queue": 4, "total": 5, "speed": 0, "download": true, "reconnect": false, "captcha": false}"?
Offline
No it doesn't (uses to work mind)
It is the answer to the first URL api/login
Offline
According to your OP it's the reply to both requests.
Offline
Sorry for any confusion, the first curl command is to log on and get the credentials to the second curl command to extract the right JSON response.
Offline
+ SessionStatus='{"error": "Unauthorized"}'
Offline
Yes, I have seen that - and it seems that the credentials are no longer past on to the second curl command.
Credentials are correct though and I can't figure out why it is isn't working any longer.
Offline
It's also actually in the original post.
Well, no, it wasn't - that was my point. What was in the OP was the expected json reply which would pruduce a "0" if piped to that jq command. As it didn't produce a zero, it was clear the actual reply to the curl command was not what was expected. This was confirmed in post 3 which makes the problem quite clear.
For the authorization error, is there a reason you are passing a different "Host" header for the two curl commands? The second one drops the port specification.
Last edited by Trilby (2023-06-08 19:59:26)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
If you enter this into a terminal
curl -s http://192.168.1.90:8000/api/statusServer -g -H 'Host: 192.168.1.90' -H 'Content-Type: application/x-www-form-urlencoded' --data 'session={
"_permanent": true,
"authenticated": true,
"id": 1,
"name": "pyload",
"role": 0,
"perms": 0,
"template": "default",
"_flashes": [
[
"message",
"Logged in successfully"
]
]
}'
what is the response.
Offline
See below the output
{"error": "Unauthorized"}
Offline
For the authorization error, is there a reason you are passing a different "Host" header for the two curl commands? The second one drops the port specification.
Offline
Sorry no reason, but I have now added the port onto the second curl command and I am still getting the error:
~]$ sh autosuspend_script/pyload_autosuspend.s
h
++ curl -s http://192.168.1.90:8000/api/login -g -H 'Host: 192.
168.1.90:8000' -H 'Content-Type: application/x-www-form-urlenco
ded' --data 'username=*****&password=****'
+ SessionID='{"_permanent": true, "authenticated": true, "id":
1, "name": "pyload", "role": 0, "perms": 0, "template": "defaul
t", "_flashes": [["message", "Logged in successfully"]]}'
++ curl -s http://192.168.1.90:8000/api/statusServer -g -H 'Hos
t: 192.168.1.90:8000' -H 'Content-Type: application/x-www-form-
urlencoded' --data 'session={"_permanent": true, "authenticated
": true, "id": 1, "name": "pyload", "role": 0, "perms": 0, "tem
plate": "default", "_flashes": [["message", "Logged in successf
ully"]]}'
+ SessionStatus='{"error": "Unauthorized"}'
+ '[' '{"error":' '"Unauthorized"}' -eq 1 ']'
autosuspend_script/pyload_autosuspend.sh: line 10: [: too many
arguments
+ exit 1
Offline
"Content-Type: application/x-www-form-urlencoded" and then send "application/json".
If I was the webserver, I'd rap the sender over the knuckles.
How is this even working?
?לאן אתה רוצה ללכת היום
Online
--data-urlencode, but the SessionID doesn't look particularily "ID" to me either.
Offline
--data-urlencode, but the SessionID doesn't look particularily "ID" to me either.
This was also my thought from the start. That output confirms a login, but there's nothing in it at all that should be resent in another query. I speculated that if this ever worked it might be due to the server maintaining a log of the authorized client IP. But now I'm starting to think it perhaps previously worked only by accident, and now it is "failing" correctly.
sweetthdevil, do you have any documentation on which this means of loging in / authenticating is recommended? From a very brief web search pyLoad appears to provide a web interface on port 8000, and if a web user logged in, they'd most likely be provided a login cookie of some sort. Curl can manage browser cookies if needed - but you don't have any code to do so in that script.
More often, if there was a (not-strictly-web) API, you'd get back a token from a login command that you would then send in subsequent requests.
Last edited by Trilby (2023-06-08 21:31:13)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline