http向AWS其他云提供商的/tracks/{id}请求403状态代码,但在本地请求200 [英] http requests to /tracks/{id} a 403 status code from AWS other cloud providers, however 200 locally
问题描述
从我们的任何AWS盒(在不同VPC内或从EC2 Classic发送)向/tracks/{id}
终端节点发送http请求返回状态403
,但是从本地计算机发送的相同http请求返回200
请求的数据.使用python的请求库和curl都会发生这种情况.
Sending http requests to the /tracks/{id}
endpoint from any of our AWS boxes, both inside of different VPCs or from EC2 Classic return 403
status codes, however the same http requests sent from local machines return 200
requested data. This happens both using python's requests library and curl.
经过Google Compute Engine和Digital Ocean的测试,它们都表现出相同的不良行为.
Tested using Google Compute Engine and Digital Ocean and both display same bad behaviour.
使用?ids
网址参数,我可以卷曲/tracks?ids=[bad_id]
using ?ids
url parameter I am able curl /tracks?ids=[bad_id]
即
不起作用:curl https://api.soundcloud.com/tracks/182343690?client_id=XXX
作品:curl https://api.soundcloud.com/tracks/?client_id=XXX&ids=182343690
i.e.
doesn't work: curl https://api.soundcloud.com/tracks/182343690?client_id=XXX
works: curl https://api.soundcloud.com/tracks/?client_id=XXX&ids=182343690
注释:都不能在请求中进行操作
note: Neither work inside requests
但是以下方法确实有效
import subprocess
subprocess.Popen("curl https://api.soundcloud.com/tracks/?client_id=XXX&ids=182343690", shell=True, stdout=subprocess.PIPE).stdout.read()
推荐答案
我不知道它是否相关,但是我在使用PHP的令牌和curl时遇到了一些问题.
I don't know if it's related, but I had some issues with tokens and curl using PHP.
最后,我在curl请求中添加了SSL选项,这解决了我的问题.
In the end I added the SSL options to my curl request and that solved my issue.
代码段
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
...
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$info = curl_getinfo($ch);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
$result = $body;
...
curl_close($ch);
} catch(Exception $e) {
$this->writeLog('authToken() Error Message: ' .$e->getMessage());
}
这篇关于http向AWS其他云提供商的/tracks/{id}请求403状态代码,但在本地请求200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!