I have been able to view the attributes of the PreparedRequest that botocore sends, but I'm wondering how I can view the exact request string that is sent to AWS. I need the exact request string to be able to compare it to another application I'm testing AWS calls with.
我可以查看botocore发送的PreparedRequest的属性,但是我想知道如何查看发送给AWS的确切请求字符串。我需要确切的请求字符串,以便能够将它与正在测试AWS调用的另一个应用程序进行比较。
2 个解决方案
#1
3
So what you probably want to do is to send your request through the proxy (mitmproxy, squid). Then check the proxy for what was sent. Since HTTPS data is encrypted you must first decrypt it, then log the response, then encrypt it back and send to AWS. One of the options is to use mitmproxy. ( It's really easy to install )
因此,您可能希望通过代理(mitmproxy, squid)发送您的请求。然后检查发送的代理。由于HTTPS数据是加密的,所以您必须首先解密它,然后记录响应,然后对其进行加密并将其发送回AWS。其中一个选项是使用mitmproxy。(安装起来很容易)
- Run mitmproxy
- 运行mitmproxy
-
Open up another terminal and point proxy to mitmproxys port:
打开另一个终端和点代理到mitmproxy端口:
export http_proxy=127.0.0.1:8080 export https_proxy=$http_proxy
-
Then set
verify=False
when creating session/client然后在创建会话/客户端时设置verify=False
In [1]: import botocore.session In [2]: client = botocore.session.Session().create_client('elasticache', verify=False)
-
Send request and look at the output of mitmproxy
发送请求并查看mitmproxy的输出
In [3]: client.describe_cache_engine_versions()
-
The result should be similar to this:
结果应与此类似:
Host: elasticache.us-east-1.amazonaws.com Accept-Encoding: identity Content-Length: 53 Content-Type: application/x-www-form-urlencoded Authorization: AWS4-HMAC-SHA256 Credential=FOOOOOO/20150428/us-east-1/elasticache/aws4_request, SignedHeaders=host;user-agent;x-amz-date, Signature=BAAAAAAR X-Amz-Date: 20150428T213004Z User-Agent: Botocore/0.103.0 Python/2.7.6 Linux/3.13.0-49-generic
<?xml version='1.0' encoding='UTF-8'?> <DescribeCacheEngineVersionsResponse xmlns="http://elasticache.amazonaws.com/doc/2015-02-02/"> <DescribeCacheEngineVersionsResult> <CacheEngineVersions> <CacheEngineVersion> <CacheParameterGroupFamily>memcached1.4</CacheParameterGroupFamily> <Engine>memcached</Engine> <CacheEngineVersionDescription>memcached version 1.4.14</CacheEngineVersionDescription> <CacheEngineDescription>memcached</CacheEngineDescription> <EngineVersion>1.4.14</EngineVersion>
#2
16
You could also enable debug logging in boto3. That will log all requests and responses as well as lots of other things. Its a bit obscure to enable it:
您还可以在boto3中启用调试日志记录。这将记录所有请求和响应以及许多其他事情。它有点晦涩:
import boto3
boto3.set_stream_logger(name='botocore')
The reason you have to specify botocore
as the name to log is that all of the actual requests and responses happen at the botocore layer.
必须指定botocore作为日志的名称的原因是所有实际的请求和响应都发生在botocore层。
#1
3
So what you probably want to do is to send your request through the proxy (mitmproxy, squid). Then check the proxy for what was sent. Since HTTPS data is encrypted you must first decrypt it, then log the response, then encrypt it back and send to AWS. One of the options is to use mitmproxy. ( It's really easy to install )
因此,您可能希望通过代理(mitmproxy, squid)发送您的请求。然后检查发送的代理。由于HTTPS数据是加密的,所以您必须首先解密它,然后记录响应,然后对其进行加密并将其发送回AWS。其中一个选项是使用mitmproxy。(安装起来很容易)
- Run mitmproxy
- 运行mitmproxy
-
Open up another terminal and point proxy to mitmproxys port:
打开另一个终端和点代理到mitmproxy端口:
export http_proxy=127.0.0.1:8080 export https_proxy=$http_proxy
-
Then set
verify=False
when creating session/client然后在创建会话/客户端时设置verify=False
In [1]: import botocore.session In [2]: client = botocore.session.Session().create_client('elasticache', verify=False)
-
Send request and look at the output of mitmproxy
发送请求并查看mitmproxy的输出
In [3]: client.describe_cache_engine_versions()
-
The result should be similar to this:
结果应与此类似:
Host: elasticache.us-east-1.amazonaws.com Accept-Encoding: identity Content-Length: 53 Content-Type: application/x-www-form-urlencoded Authorization: AWS4-HMAC-SHA256 Credential=FOOOOOO/20150428/us-east-1/elasticache/aws4_request, SignedHeaders=host;user-agent;x-amz-date, Signature=BAAAAAAR X-Amz-Date: 20150428T213004Z User-Agent: Botocore/0.103.0 Python/2.7.6 Linux/3.13.0-49-generic
<?xml version='1.0' encoding='UTF-8'?> <DescribeCacheEngineVersionsResponse xmlns="http://elasticache.amazonaws.com/doc/2015-02-02/"> <DescribeCacheEngineVersionsResult> <CacheEngineVersions> <CacheEngineVersion> <CacheParameterGroupFamily>memcached1.4</CacheParameterGroupFamily> <Engine>memcached</Engine> <CacheEngineVersionDescription>memcached version 1.4.14</CacheEngineVersionDescription> <CacheEngineDescription>memcached</CacheEngineDescription> <EngineVersion>1.4.14</EngineVersion>
#2
16
You could also enable debug logging in boto3. That will log all requests and responses as well as lots of other things. Its a bit obscure to enable it:
您还可以在boto3中启用调试日志记录。这将记录所有请求和响应以及许多其他事情。它有点晦涩:
import boto3
boto3.set_stream_logger(name='botocore')
The reason you have to specify botocore
as the name to log is that all of the actual requests and responses happen at the botocore layer.
必须指定botocore作为日志的名称的原因是所有实际的请求和响应都发生在botocore层。