我试图在SAS中使用curl从api下载数据。我有一个消费者密钥,消费者密钥,OAuth令牌,& OAuth令牌密钥。看起来我可以连接到API,但我收到一个错误,指出“HTTP传输:无法确定内容的长度”。有没有人有任何见解或想法?非常感谢。在sas中使用curl:api的oauth请求
代码:
dm 'clear log';
options;
%let consumer_key =;
%let consumer_secret=;
%let oauth_token=;
%let oauth_token_secret=;
filename curl pipe "curl -X POST -k https://api.tradeking.com/v1/market/ext/quotes.xml?symbols=aapl --verbose --header
'Authorization:OAuth oauth_nonce=4572616e48616d6d65724c61686176,oauth_timestamp=1359019570,oauth_version=1.0,
oauth_signature_method=HMAC-SHA1,oauth_consumer_key={&consumer_key.},oauth_consumer_key_secret={&consumer_secret.},
oauth_token={&oauth_token.},oauth_token_secret={&oauth_token_secret.}";
data _null_;
infile curl lrecl=32767;
input;
put _infile_;
run;
登录:
dm 'clear log';
options;
636
637 %let consumer_key =;
638 %let consumer_secret=;
639 %let oauth_token=;
640 %let oauth_token_secret=;
641
642 filename curl pipe "curl -X POST -k
642! https://api.tradeking.com/v1/market/ext/quotes.xml?symbols=aapl --verbose --header
643 'Authorization:OAuth
643! oauth_nonce=4572616e48616d6d65724c61686176,oauth_timestamp=1359019570,oauth_version=1.0,
WARNING: The quoted string currently being processed has become more than 262 characters long.
You might have unbalanced quotation marks.
644 oauth_signature_method=HMAC-SHA1,oauth_consumer_key={&consumer_key.},oauth_consumer_ke
644! y_secret={&consumer_secret.},
645 oauth_token={&oauth_token.},oauth_token_secret={&oauth_token_secret.}";
646
647 data _null_;
648 infile curl lrecl=32767;
649 input;
650 put _infile_;
651 run;
NOTE: The infile CURL is:
Unnamed Pipe Access Device,
PROCESS=curl -X POST -k https://api.tradeking.com/v1/market/ext/quotes.xml?symbols=aapl
--verbose --header 'Authorization:OAuth
oauth_nonce=4572616e48616d6d65724c61686176,oauth_timestamp=1359019570,oauth_version=1.0,
oauth_signature_method=HMAC-SHA1,oauth_consumer_key={
JXpV},oauth_consumer_key_secret={},
oauth_token={},oauth_token_secret={},
RECFM=V,LRECL=32767
Fault Name: HttpRequestReceiveError
Error Type: Default
Description: Http request received failed
Root Cause Code: -19013
Root Cause : HTTP Transport: Couldn't determine the content length
Binding State: CLIENT_CONNECTION_ESTABLISHED
Service: null
Endpoint: null
Operation (Client):
--_curl_--oauth_signature_method=HMAC-SHA1,oauth_consumer_key=
--_curl_--oauth_token=,oauth_token_secret=Q
Stderr output:
* Adding handle: conn: 0x1ea8850
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x1ea8850) send_pipe: 1, recv_pipe: 0
Total Received Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* About to
connect() to api.tradeking.com port 443 (#0)
* Trying 206.132.7.9...
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to
api.tradeking.com (206.132.7.9) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Server hello (2):
{ [data not shown]
* SSLv3, TLS handshake, CERT (11):
{ [data not shown]
* SSLv3, TLS handshake, Server finished (14):
{ [data not shown]
* SSLv3, TLS handshake, Client key exchange (16):
} [data not shown]
* SSLv3, TLS change cipher, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Finished (20):
} [data not shown]
* SSLv3, TLS change cipher, Client hello (1):
{ [data not shown]
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0* SSLv3, TLS
handshake, Finished (20):
{ [data not shown]
* SSL connection using RC4-MD5
* Server certificate:
* subject: OU=Domain Control Validated; OU=COMODO SSL Wildcard; CN=*.tradeking.com
* start date: 2013-06-09 00:00:00 GMT
* expire date: 2016-06-08 23:59:59 GMT
* issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO SSL CA
* SSL certificate verify result: self signed certificate in certificate chain (19),
continuing anyway.
> POST /v1/market/ext/quotes.xml?symbols=aapl HTTP/1.1
> User-Agent: curl/7.33.0
> Host: api.tradeking.com
> Accept: */*
> 'Authorization:OAuth
>
< HTTP/1.1 411 Length Required
< Connection: close
< Content-Length: 284
<
{ [data not shown]
100 284 100 284 0 0 178 0 0:00:01 0:00:01 --:--:-- 178
* Closing connection 0
* SSLv3, TLS alert, Client hello (1):
} [data not shown]
* Rebuilt URL to:
oauth_nonce=4572616e48616d6d65724c61686176,oauth_timestamp=1359019570,oauth_version=1.0,/
* Adding handle: conn: 0x1f00560
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 1 (0x1f00560) send_pipe: 1, recv_pipe: 0
* Could not resolve host:
oauth_nonce=,oauth_timestamp=1359019570,oauth_version=1.0,
* Closing connection 1
curl: (6) Could not resolve host:
oauth_nonce=4572616e48616d6d65724c61686176,oauth_timestamp=1359019570,oauth_version=1.0,
[1/3]:
oauth_signature_method=HMAC-SHA1,oauth_consumer_key=
--> <stdout>
* Rebuilt URL to:
oauth_signature_method=HMAC-SHA1,oauth_consumer_key=
/
* Adding handle: conn: 0x1ef10e0
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 2 (0x1ef10e0) send_pipe: 1, recv_pipe: 0
* Could not resolve host:
oauth_signature_method=HMAC-SHA1,oauth_consumer_key=
* Closing connection 2
curl: (6) Could not resolve host:
oauth_signature_method=HMAC-SHA1,oauth_consumer_key=
[1/2]:
oauth_token=,oauth_token_secret=
--> <stdout>
* Rebuilt URL to:
oauth_token=,oauth_token_secret=
/
* Adding handle: conn: 0x1ef56c0
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 3 (0x1ef56c0) send_pipe: 1, recv_pipe: 0
* Could not resolve host:
oauth_token=,oauth_token_secret=
* Closing connection 3
curl: (6) Could not resolve host:
oauth_token=,oauth_token_secret=
NOTE: 12 records were read from the infile CURL.
The minimum record length was 0.
The maximum record length was 174.
NOTE: DATA statement used (Total process time):
real time 1.84 seconds
cpu time 0.23 seconds
如果您通过网络浏览器获取相同的数据,是否有任何发送的头文件您未在代码中发送,可能需要这些头文件才能使其工作? – user667489 2014-11-01 09:55:34
感谢您的想法。你如何通过网络浏览器测试api?我安装了ActivePython-2.7.8.10-win64-x64和Twisted-14.0.2.win-amd64-py2.7,但没有任何工作。有更容易的方法吗? – user3806824 2014-11-02 06:38:41
对不起,当我看到你的问题时,那部分没有正确扫描。尽管如此,一般的观点仍然适用 - 如果你有一个有效的API调用示例(即不使用cURL),请查看产生的流量,并查看是否有任何内容离开cURL调用。 – user667489 2014-11-02 08:55:02