将cookie作为dict转换为cookie作为HTTP请求的字符串

时间:2015-06-08 21:43:23

标签: python

我有以下cookie,存储为dict:

cookies = session.cookies.get_dict()
{'nflx-rgn': '"ue1|1433799654706|uw2:2"', 'SecureNetflixId': 'v%3D2%26mac%3DAQEAEQABABTh6lNR0cbOgGRD7DT7CChBIhA83qsfV_k.%26dt%3D1433799654968', 'memclid': '9a55d2c6-4d85-44bb-8338-0b1a180a7c44', 'NetflixId': 'v%3D2%26ct%3DBQAOAAEBEFP07qwktIitvHYO-Xn6gU2BYKymzutSFtIyfD_zEWVo4yMjbjJ4LgPmtZhjgE5lRWg5OTP8C1N2zNbTc8VsdzUS3OaLnsGsV4AkXZzkewt0X0WcMwSYVl3-pX8Rs0jH2PCXixD8K2oARmtQIrWCvv35EUOpGCb3v-tExqpZaN_6FBfTrF68FXcR4kDGAjXYooBWKnCv1aS1VVscso_GRg6HH7--qOsjW7WoPkxyRAAqt0GmeD8tY5aQHMbD779s7oiAr7YArEmUC_3Hdej0huyGo0Iq-_IlY_jGZhyupIO0ZIpznvGB2teF8YeaiSh2LlQ4RIlUOo3hO5n9lmlmBnRXAYGYbJ_64HiwTfsw3jRWkgAJWnnxSHo9sGLJibspLCQ3RzdA-JwxSPYoBh-HkhnAxxPveWmPbH_1JtXR9rvhfnenIhDgzu_nCUH7i-sxg4bnKhGjpVzH1Y8x9wSNE2-xWdax912FBEzQWyT5I2HxnQQ.%26bt%3Dusr%26ch%3DAQEAEAABABRxRbrqqSNQFSxPcuqeaLCNvVMfYe40K6A.%26mac%3DAQEAEAABABTQs51fmHZefZn26dZQFm9ZDMjlNgmXis8.', 'tlr': 'US|1433799655947'}

然后我如何将其添加到我的请求标头中,以便它有效。例如:

headers = {
        "Accept-Language" : "en-US,en;q=0.8,pt;q=0.6",
        "Connection" : "keep-alive",
        "Cookies": ???
}
requests.get(url, headers=headers)

我更愿意将cookies参数添加到请求中。

1 个答案:

答案 0 :(得分:9)

使用此:

chart = new Highcharts.Chart({
    chart: {
        renderTo: 'final',
        defaultSeriesType: 'spline',
        events: {
            load: function()
            {
              setTimeout(function(){
                 $.ajax({
                    url: 'test',
                    type: 'GET',
                    async: true,
                    dataType: "json",
                    success: function (data) {
                      console.log(data);
                      chart.setData(data,true);
                        //chart.setData(data,true);
                    }
                  });
              }, 10000);                  
            }
        }
    },
    title: {
        text: 'Live random data'
    },
    xAxis: {
        type: 'datetime',
        tickPixelInterval: 150,
        maxZoom: 20 * 1000
    },
    yAxis: {
        minPadding: 0.2,
        maxPadding: 0.2,
        title: {
            text: 'Value',
            margin: 80
        }
    },
    series: []
});