thorsten-gehrig / alexa-remote-control

control Amazon Alexa from command Line (set volume, select station from tunein or pandora)
416 stars 102 forks source link

Multiple errors "date: invalid date" #163

Closed nodev11 closed 7 months ago

nodev11 commented 1 year ago

The last modification causes multiple errors during the login process (after deleting /tmp/.alexa.*).

date: invalid date '...'
date: invalid date '...'
date: invalid date '...'
Korki67 commented 1 year ago

hi there, I also get this sometimes when I login using refresh token:

date: invalid date '15.09.2042 22:45:43 GMT'

I got this on 15.09.2022 22:45:43 GMT, so it seems someone added 20 years ... Despite error message, all is working fine and seems to have no impact. I assume it is an error at Amazon and not an error in the great script here ...

Regards, Horst

nodev11 commented 1 year ago

The errors are thrown by the function "toEpoch()" which calls the "date" command multiple times with wrong parameters.

nigels0 commented 1 year ago

I’m getting this:

core-ssh alexa]$ ./alexa_remote_control.sh -a cookie expired, logging in again ... date: invalid date '24 Feb 2043 02:55:39 GMT' date: invalid date '24 Feb 2043 02:55:39 GMT' date: invalid date '24 Feb 2043 02:55:39 GMT' date: invalid date '2 Mar 2023 02:55:39 GMT' date: invalid date '2 Mar 2023 02:55:39 GMT' trying to get CSRF from handlebars trying to get CSRF from devices-v2 ERROR: no CSRF cookie received

Tloram commented 1 year ago

I’m getting this:

core-ssh alexa]$ ./alexa_remote_control.sh -a cookie expired, logging in again ... date: invalid date '24 Feb 2043 02:55:39 GMT' date: invalid date '24 Feb 2043 02:55:39 GMT' date: invalid date '24 Feb 2043 02:55:39 GMT' date: invalid date '2 Mar 2023 02:55:39 GMT' date: invalid date '2 Mar 2023 02:55:39 GMT' trying to get CSRF from handlebars trying to get CSRF from devices-v2 ERROR: no CSRF cookie received

Same issue here. Started about a month ago, have not found a solution yet.

Korki67 commented 1 year ago

Hi there,

please note again that I am just another very happy user of this wonderful script.

My system is still working fine. I did get and I may still do get the error of the year 2043-ish. In my system, it is only a nuisance but does not cause any real problem. All is working fine.

Are you using the refresh_token? I am using it. Perhaps you create a new refresh_token?

It may be that you got two issues: a real one that is causing "no cookie received" plus the fake one of 2043 messages?

Regards, Horst

anyone2 commented 1 year ago

macOS and few other platforms do not have a '-d' option for the date command.

date: illegal option -- d usage: date [-jnRu] [-r seconds|file] [-v[+|-]val[ymwdHMS]] [-I[date | hours | minutes | seconds]] [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

So the last update is not going work on some platforms. They will need to keep using the prior version.

Do you need to perform the toEpoch() function on all systems?

Also...like the previous person...extremely happy with this project.

adn77 commented 1 year ago

We're receiving a JSON string with cookie expiration dates in the form 24 Feb 2043 02:55:39 GMT I first tried using JQ's strptime for converting that to a Unix timestamp (as curl expects it in its cookie jar). If that worked for you - stick with v0.20d. Unfortunately this was dependent on JQ's version.

If somebody has a more portable approach, let's try that 😃

nodev11 commented 1 year ago

So the solution is simple as that?

# date -d "24 Feb 2043 02:55:39 GMT" -u +"%s"
date: invalid date '24 Feb 2043 02:55:39 GMT'
# date -D "24 Feb 2043 02:55:39 GMT" -u +"%s"
1687427313
anyone2 commented 1 year ago

Neither "-d" nor "-D" are available in macOS and other BSD-based systems. Below is the equivalent command.


 :date -j -f "%d %b %Y %H:%M:%S %Z" "24 Feb 2043 02:55:39 GMT" +"%s"
2308359339

 :date -d "24 Feb 2043 02:55:39 GMT" -u +"%s"
date: illegal option -- d
usage: date [-jnRu] [-I[date|hours|minutes|seconds]] [-f input_fmt]
            [-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]
            [[[[mm]dd]HH]MM[[cc]yy][.SS] | new_date] [+output_fmt]

 :date -D "24 Feb 2043 02:55:39 GMT" -u +"%s"
date: illegal option -- D
usage: date [-jnRu] [-I[date|hours|minutes|seconds]] [-f input_fmt]
            [-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]
            [[[[mm]dd]HH]MM[[cc]yy][.SS] | new_date] [+output_fmt]
 :
adn77 commented 7 months ago

I added a detection for OSX and BSD.

@nodev11 what OS are you using? I don't find date -D anwhere...

nodev11 commented 7 months ago

I added a detection for OSX and BSD.

Sadly this doesn't work for me (same errors), so I modified v0.21 (using jq's strptime function again).

@nodev11 what OS are you using? I don't find date -D anwhere...

BusyBox v1.29.2 multi-call binary.

Usage: date [OPTIONS] [+FMT] [TIME]

Display time (using +FMT), or set time

        [-s,--set] TIME Set time to TIME
        -u,--utc        Work in UTC (don't convert to local time)
        -R,--rfc-2822   Output RFC-2822 compliant date string
        -I[SPEC]        Output ISO-8601 compliant date string
                        SPEC='date' (default) for date only,
                        'hours', 'minutes', or 'seconds' for date and
                        time to the indicated precision
        -r,--reference FILE     Display last modification time of FILE
        -d,--date TIME  Display TIME, not 'now'
        -D FMT          Use FMT for -d TIME conversion

Recognized TIME formats:
        hh:mm[:ss]
        [YYYY.]MM.DD-hh:mm[:ss]
        YYYY-MM-DD hh:mm[:ss]
        [[[[[YY]YY]MM]DD]hh]mm[.ss]
        'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead
adn77 commented 7 months ago

I tried something different now. In theory we can instruct the shell not to exit on error. Next I simply try all the different date commands we know.

https://raw.githubusercontent.com/adn77/alexa-remote-control/master/alexa_remote_control.sh

If it works, I will PR this later today.

nodev11 commented 7 months ago

https://raw.githubusercontent.com/adn77/alexa-remote-control/master/alexa_remote_control.sh

If it works, I will PR this later today.

Works for me. No errors were thrown. Well done!

nodev11 commented 7 months ago

Problem fixed by adn77 Thanks a lot!