使用 SAS EG 通过代理从 API 下载 JSON 文件

2024-05-05

我正在尝试使用瑞士当局提供的 API 对公司网络内的地址进行地理编码。我的公司使用带有用户名和密码的代理服务器。我是 SAS EG 的新手,这是我迄今为止拥有的代码(我必须匿名一些内容才能被允许在此处发布):

filename response temp;
options set=SSL_USE_SNI=1;
options set=SSL_SNI_HOSTNAME="api3.geo.admin.ch";
proc http
url = 'https://api3.geo.admin.ch/rest/services/api/SearchServer?searchText=Bahnhofstrasse %201%20Zürich&type=locations'
method='GET'
proxyhost = 'http://OURPROXYHOST.ch'
proxyport = 8080
proxyusername = '***'
proxypassword= '***'
out= response
ct = "application/json";
run;

但是,日志不会抛出任何错误或警告,并且运行代码时我没有看到任何输出文件。如果我在浏览器中输入网址,它就会起作用。

我使用的是 SAS EG 7.15 HF7 (7.100.5.6177)(64 位)。我希望你们能在这里帮助我。


输出头是什么样子的,用户HEADEROUT=看看

示例代码(尽管没有代理)

filename response temp;
filename headers  temp;

proc http
  url    = "https://worldpopulationreview.com/static/states/abbr-name.json"
  method = "get"
  out    = response
  ct     = "application/json"
  headerout = headers
;

data _null_;
  infile headers;
  input; 
  put _infile_;
run;

data _null_;
  infile response obs=10;
  input;
  put _infile_;
run;

* libref name same as fileref pointing to json content;
libname response json;

proc copy in=response out=work;
run;

Log

93     headerout = headers
94   ;
95

NOTE: 200 OK
NOTE: PROCEDURE HTTP used (Total process time):
      real time           0.04 seconds
      cpu time            0.00 seconds


96   data _null_;
97     infile headers;
98     input;
99     put _infile_;
100  run;

NOTE: The infile HEADERS is:
      Filename=C:\Users\Richard\AppData\Local\Temp\SAS Temporary Files\_TD4224_HELIUM_\#LN00067,
      RECFM=V,LRECL=32767,File Size (bytes)=531,
      Last Modified=05Nov2020:09:39:53,
      Create Time=05Nov2020:09:39:53

HTTP/1.1 200 OK
Date: Thu, 05 Nov 2020 14:39:55 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
content-disposition: inline; filename="abbr-name.json"
cache-control: public, max-age=0, must-revalidate
content-length: 1057
access-control-allow-origin: *
etag: W/"672e384a87acd2f6547e5127fde8f2fe74c991498d7b468b1e439c3860554ea8"
accept-ranges: bytes
x-vercel-cache: HIT
age: 189
server: Vercel
x-vercel-id: cle1::fz9dn-1604587195926-0957f649b2c8
strict-transport-security: max-age=63072000
NOTE: 16 records were read from the infile HEADERS.
      The minimum record length was 0.
      The maximum record length was 74.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


101
102  data _null_;
103    infile response obs=10;
104    input;
105    put _infile_;
106  run;

NOTE: The infile RESPONSE is:
      Filename=C:\Users\Richard\AppData\Local\Temp\SAS Temporary Files\_TD4224_HELIUM_\#LN00066,
      RECFM=V,LRECL=32767,File Size (bytes)=1057,
      Last Modified=05Nov2020:09:39:53,
      Create Time=05Nov2020:09:39:53

{
  "AL": "Alabama",
  "AK": "Alaska",
  "AZ": "Arizona",
  "AR": "Arkansas",
  "CA": "California",
  "CO": "Colorado",
  "CT": "Connecticut",
  "DE": "Delaware",
  "DC": "District Of Columbia",
NOTE: 10 records were read from the infile RESPONSE.
      The minimum record length was 1.
      The maximum record length was 31.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


107
108  * libname same as fileref pointing to json content;
109  libname response json;
NOTE: JSON data is only read once.  To read the JSON again, reassign the JSON LIBNAME.
NOTE: Libref RESPONSE was successfully assigned as follows:
      Engine:        JSON
      Physical Name: C:\Users\Richard\AppData\Local\Temp\SAS Temporary
      Files\_TD4224_HELIUM_\#LN00066
110
111  proc copy in=response out=work;
112  run;

NOTE: Copying RESPONSE.ALLDATA to WORK.ALLDATA (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 51 observations read from the data set RESPONSE.ALLDATA.
NOTE: The data set WORK.ALLDATA has 51 observations and 4 variables.
NOTE: Copying RESPONSE.ROOT to WORK.ROOT (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 1 observations read from the data set RESPONSE.ROOT.
NOTE: The data set WORK.ROOT has 1 observations and 52 variables.
NOTE: PROCEDURE COPY used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds

第一个表复制到工作(ROOT)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 SAS EG 通过代理从 API 下载 JSON 文件 的相关文章

随机推荐