首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SAS API请求产生“非法字符”错误

SAS API请求产生“非法字符”错误
EN

Stack Overflow用户
提问于 2021-02-19 01:22:13
回答 1查看 196关注 0票数 1

我正在尝试使用需要登录的地理编码器通过代理对公司网络中的地址进行地理编码。在浏览器中,我只需要在第一次尝试时输入一次登录凭据。

我以前将下面的代码用于不同的地理编码器(没有身份验证),它工作得很好。我把它当作是对a previous question的一个回答。但是,对于本例,它返回以下错误:

代码语言:javascript
复制
59         * libref name same as fileref pointing to json content;
60         libname response json;
NOTE: JSON data is only read once.  To read the JSON again, reassign the JSON LIBNAME.
ERROR: Invalid JSON in input near line 1 column 1: Encountered an illegal character.
ERROR: Error in the LIBNAME statement.

与其他代码相比,我只添加了webusernamewebpassword,但是否使用它对错误消息没有影响。除此之外,我只更改了选项set=SSL_SNI_HOSTNAMEurl=的URL。

代码语言:javascript
复制
filename response temp;
filename headers temp;

options set=SSL_USE_SNI=1;
options set=SSL_SNI_HOSTNAME="https://geocoder.srv"; /*<-- this might be wrong, i took it from the start of the url */
proc http
url = 'SORRY NOT ALLOWED TO PUT THE URL HERE'
method='GET'
proxyhost = 'OUR WEBPROXY'
webusername = 'USERNAME'
webpassword = 'PW'
proxyport = 8080
out= response
headerout = headers
ct = "application/json";
run;


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;
EN

回答 1

Stack Overflow用户

发布于 2021-02-19 02:42:36

这通常意味着在请求过程中出现了错误,并且站点没有返回JSON文件。要诊断返回的消息,请添加debug语句(info)。使用选项RESPONSE_BODY RESPONSE_TEXT返回日志中的响应。

代码语言:javascript
复制
proc http 
    url       = "www.google.com"
    proxyhost = "my proxy"
    proxyport = 8080
    ;
    debug RESPONSE_BODY OUTPUT_TEXT;
run;

响应:

代码语言:javascript
复制
< <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's 
information, including webpages, images, videos and more.
....

您可以通过删除RESPONSE_BODY来进一步简化响应。

代码语言:javascript
复制
NOTE: 200 OK

如果您的SAS版本不支持这些选项,您可以通过将响应重定向到您的主目录并打开该文件来执行相同的操作。例如:

代码语言:javascript
复制
filename response "/home/$USER/response.txt";

proc http
    url = "www.google.com"
    out = response
    ...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66264970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档