本文介绍了使用SAS EG通过代理从API下载JSON文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用瑞士当局提供的API对公司网络中的地址进行地理编码.我公司使用具有用户名和密码的代理服务器.我是SAS EG的新手,这是我到目前为止的代码(我不得不匿名化一些东西以便允许在此处发布):

I am trying to geocode adresses from within a company network using an API from the Swiss authorities. My company uses proxy servers with usernames and passwords. I am new to SAS EG and this is the code that I have so far (i had to anonymize some things in order to be allowed to post this here):

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;

但是,该日志不会引发任何错误或警告,并且在运行代码时看不到任何输出文件.如果我在浏览器中输入网址,那么它将起作用.

The log does however not throw any errors or warnings and I am seeing no output file when running the code. If I enter the url into the browser it works.

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

I'm using SAS EG 7.15 HF7 (7.100.5.6177) (64-Bit). I hope you guys can help me out here.

推荐答案

输出标头是什么样的,用户HEADEROUT =要查看

What do the output headers look like, user HEADEROUT= to see

示例代码(虽然没有代理)

Sample code (no proxy though)

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;

日志

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)

First table copied to work (ROOT)

这篇关于使用SAS EG通过代理从API下载JSON文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 21:29