frank1 has asked for the wisdom of the Perl Monks concerning the following question:
Am having a problem with my script
Am getting this error
{"label":"REQUEST_EXPIRED","message":"gap between request Timestamp and server time exceeds 60"} HTTP POST error code: 403 HTTP POST error message: Forbidden
This is the API shell example
key="YOUR_API_KEY" secret="YOUR_API_SECRET" host="https://api.gateio.ws" prefix="/api/v4" method="POST" url="/withdrawals" query_param="" body_param='{"withdraw_order_id":"order_123456","currency":"USDT","add +ress":"1HkxtBAMrA3tP5ENnYY2CZortjZvFDH5Cs","amount":"222.61","memo":" +","chain":"TRX"}' timestamp=$(date +%s) body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}') sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestam +p" sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{ +print $NF}') full_url="$host$prefix$url" curl -X $method $full_url -d "$body_param" -H "Content-Type: applicati +on/json" \ -H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign"
This is my code
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use JSON qw( encode_json ) use Digest::SHA qw(hmac_sha512_hex); use MIME::Base64; use POSIX qw( strftime ); my $apiKey = 'demo'; my $host = "https://api.gateio.ws"; my $prefix = "/api/v4"; my $url = '/withdrawals'; my $query_param = ''; my %mas = ( "amount" => "222.61", "currency" => "USDT", "address" => "1HkxtBAMrA3tP5ENnYY2CZortjZvFDH5Cs", "chain" => "TRX" ); my $body = encode_json \%mas; my $time = time; my $timestamp = strftime("%Y%m%d %S", localtime($time)); my $sign_headers = hmac_sha512_hex('POST', $prefix . $url, $query_para +m, $body, $timestamp); my %payload = ( "KEY" => $apiKey, "Timestamp" => $timestamp, "SIGN" => $sign_headers, "Content-Type" => 'application/json' ); my $ua = LWP::UserAgent->new; my $response = $ua->post( $host . $prefix . $url, %payload, Content => $body ); if ($response->is_success) { print $response->decoded_content; } else { print $response->decoded_content; print "HTTP POST error code: ", $response->code, "\n"; print "HTTP POST error message: ", $response->message, "\n"; }
I believe the problem is here
Example indicates
timestamp=$(date +%s)
And me am doing it this way
my $time = time; my $timestamp = strftime("%Y%m%d %S", localtime($time)); # prints example 20240924 55
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: REQUEST EXPIRED
by Corion (Patriarch) on Sep 24, 2024 at 17:31 UTC | |
by frank1 (Monk) on Sep 24, 2024 at 18:29 UTC | |
by Danny (Chaplain) on Sep 24, 2024 at 20:39 UTC | |
|
Re: REQUEST EXPIRED
by marto (Cardinal) on Sep 24, 2024 at 16:42 UTC | |
by frank1 (Monk) on Sep 24, 2024 at 17:15 UTC |