Thread Wettervorhersage API (6 answers)
Opened by bianca at 2023-04-08 10:43

bianca
 2023-04-08 12:29
#194779 #194779
User since
2009-09-13
6978 Artikel
BenutzerIn

user image
Bin ein Stück weiter und brauche bitte Hilfe.
Der Stand:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl
use strict;
use warnings;

my %req_json = (
    date            => '2021-03-24',
    time            => ['00:00','06:00','12:00','18:00'],
    leadtime_hour   => '0',
    area            => [70, -18, 69, -17],          # North, West, South, East
    type            => 'analysis',
    variable        => 'total_aerosol_optical_depth_670nm',
    format          => 'netcdf_zip',
);
require JSON; JSON->import('-support_by_pp');
my $req_json_string = JSON->new->latin1->escape_slash()->encode(\%req_json);

require HTTP::Request;
my $request = HTTP::Request->new(POST => 'https://ads.atmosphere.copernicus.eu/api/v2');
$request->header('content-type' => 'application/json');
$request->header('accept' => 'application/json');
$request->content('cams-global-atmospheric-composition-forecasts',$req_json_string,'download.netcdf_zip');
$request->authorization_basic('meine uid','mein api key');

require IO::Socket::SSL;
IO::Socket::SSL->import(qw(SSL_VERIFY_NONE));
require LWP::UserAgent;
my $ua = LWP::UserAgent->new(
    cookie_jar      => {},
    agent           => 'Perl',
    timeout         => 10,
    ssl_opts        => {
        SSL_verify_mode => SSL_VERIFY_NONE(),
        verify_hostname => 0,
    }
) or do { die; };
my $response = $ua->request($request);

if ($response->is_success) {
    my $content = $response->decoded_content;
say $content;
}
else { die $response->status_line; }

Ausgabe:
Quote
404 Not Found at cams_api_forum.pl line 42.

Ich vermute, es liegt an Zeile 21: $request->content('cams-global-atmospheric-composition-forecasts',$req_json_string,'download.netcdf_zip'). Aber wie muss das richtig lauten?
In der Doku https://confluence.ecmwf.int/display/CKB/CAMS%3A+G... steht dieses folgende Beispiel aber ich weiß nicht, wie man das auf Perl'sch übersetzt:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import cdsapi
c = cdsapi.Client()
c.retrieve(
'cams-global-atmospheric-composition-forecasts',
{
'date': '2021-03-24',
'time': [
'00:00', '06:00', '12:00',
'18:00',
],
'leadtime_hour': '0',
'area': [ #North, West, South, East
70, -18, 69,
-17,
],
'type':'analysis',
'variable': 'total_aerosol_optical_depth_670nm',
'format': 'netcdf_zip',
},
'download.netcdf_zip')

Kann mir bitte jemand beim Aufbau des Requests helfen und als Frage: wie setzt man die Doku in ein Perl request um?
10 print "Hallo"
20 goto 10

View full thread Wettervorhersage API