我正在尝试向我的交易账户发送网页请求。 Python无法解码Web请求。使用代码200的Web请求成功。
以下是代码
import requests
headers = {
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.9',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
'x-kite-version': '1.2.1',
'accept': 'application/json, text/plain, */*',
'referer': 'https://kite.zerodha.com/orders',
'authority': 'kite.zerodha.com',
'cookie': '__cfduid=db8fb54c76c53442fb672dee32ed58aeb1521962031; _ga=GA1.2.1516103745.1522000590; _gid=GA1.2.581693731.1522462921; kfsession=CfawFIZq2T6SghlCd8FZegqFjNIKCYuO; public_token=7FyfBbbxhiRRUso3425TViK2VmVszMCK; user_id=XE4670',
'x-csrftoken': '7FyfBbbxhiRRUso3425TViK2VmVszMCK',
}
response = requests.get('https://kite.zerodha.com/api/orders', headers=headers)
x=str(response.content.decode("utf-8") )
b“1X \ x14 \ x00 \ xfe \ xa7 \ x9b \ xd3 \ xca \ xbd9- \ x12 \ x83 \ xbfULS1 \ x1d8 \ x9d \ x0e \ xd4 \ xcf \ xbd \ xb8 \ xd1 \ xbd4 \ xc0 \ X00 \ X13〜\ X94} \ XE4 \ X81 \ XA4 \ x90P \ x1cfs \ XCD \ X1E \ xaeG \ x9b},米\ XBD \吨\ x84L1 \ XDE \ xa8e \ x8a \ xf1h \ x0e \ X0C)\ X1A \ x12 \ xfb \ x06z \ xec \ x18 \ xe4r \ xa1 \ x1c \ x11 \ xe8 \ xbcO \ xec \ xe2 | \ xa6 \ x90 \ xa9 \ xdf \ xf2 \ xe1 \ xfa \ xf3 \ x1e \ x04 \ x0e \ xa2 \ x8d \ x0e \ XC4 \ TW \ XEB \ xd9 \ XBA \ n \ xf1H'l \ XEB> \ X08 \ x85L \ r \ x0cY \ XF8 \ x81D; \ X92ø\ XFD \ XBD \ xe3u>!3 \ X10 \ XE1 \ x8c; \ XB8 \ x9e \ xceA \ XAE \ x0exX \ xc9 \ x19s \ XEB \ xe5r〜1 \ X98 \ xed0 \ XB8 \ XDC \ XB4 \ X17:\ X14 \ x96xAn \ xb9 \ XF0 \ XCE \ XF2L \\ xa6G?50 \ x9b \ XF3 \ XC1 \\ X1F \ X0F \ x8fs \ X1B / \ X17 \ X1A \ X0C [ySAX \ X1D'\ XE7 \ XBB \ NX \ xacR〜\ XBB \ x9f \ xe0 \ x8c?小号\ XC0 \ X8F \ xe0 \ X97 \ XFF \ XDE'\ xc7#\ X8F \ X97 \ XAF \的Xaa%\ XF2 \ xf9 \ xfaC | \ XCF \ t \ XF3 \ XEB \的Xaa \ XDCS \ XCC \ XF5 \ xa3RM \ xbaOY \ XF5 \ x9fe \ XFC \ X07 \ XFF \ X01"
无法对此进行解码。尝试了unicode-utf 8和stakoverflow上可用的各种代码,但失败了。
答案 0 :(得分:7)
根据response.headers
(您未提供,但可以通过运行代码轻松恢复),响应使用Brotli compression(Content-Encoding': 'br'
)进行编码。您可以使用brotlipy解压缩它:
import brotli
brotli.decompress(response.content)
#b'{"status":"success","data":[{"placed_by":"XE4670","order_id":"180331000000385",
#"exchange_order_id":null,"parent_order_id":null,"status":"REJECTED",
#"status_message":"ADAPTER is down","order_timestamp":"2018-03-31 07:59:42",
#"exchange_update_timestamp":null,...}
现在,它是JSON,正如所承诺的那样('Content-Type': 'application/json'
)。
答案 1 :(得分:0)
我通过更改请求标头解决了这个问题,
.checkbox{
top: -2px;
left:-45px;
width: 21px;
height: 21px;
opacity: 1;
display: inline-block;
margin-left:12px;
position: absolute;
}
.checkbox::after{
background: #DE1F48;
color: #30333F;
}
.checkbox:checked{
background: #DE1F48;
color: #30333F;
}
.checkbox input[type=checkbox]:checked {
background: #DE1F48;
color: #30333F;
}
到
RewriteEngine on
##1st rule with one parameter: $id--
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} id=([0-9]+) [NC]
RewriteRule ^file\.php$ /directory/%1? [R=301,L,NC]
RewriteRule ^directory/(\d+)/?$ /directory/file.php?id=$1 [L,QSA,NC]
##Parameters are $id and $class
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&class=(\w+-class)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(\w+-class)/?$ /directory/file.php?id=$1&class=$2 [NC,L,QSA]
##Rule with two parameters: $id and $name--
RewriteCond %{THE_REQUEST} \s/file\.php\?id=(\d+)&name=(\S+)\s [NC]
RewriteRule ^ /directory/%1/%2? [R=301,L]
RewriteRule ^directory/(\d+)/(.*)/?$ /directory/file.php?id=$1&name=$2 [NC,L,QSA]