Headers not sending correctly with python 2.6.6 and httplib -
i have basic python script using hit specific endpoint. reason cannot send authorization header need send on specific server. information below fictitious example of doing. wrote script runs fine on virtual machine not on actual server. python version both 2.6.6. can't change version, please don't suggest updating. writing question guidance why header might getting removed.
the environments literally identical , use configuration manager maintain consistency of settings.
here script. pretty straight forward. i'm making api call return user model based on access token.
#! /usr/bin/env python import httplib, os, socket conn = httplib.httpconnection(socket.gethostname()) conn.set_debuglevel(1) conn.putrequest("get", "/api/index.php/user") conn.putheader('authorization','bearer 123456') conn.endheaders() response = conn.getresponse() print response.status print response.reason print response.read() request & debug info on vm
[root@vm scripts]# ./test.py send: 'get /api/index.php/user http/1.1\r\n host: vm.shibby.com\r\n accept-encoding: identity\r\n authorization: bearer 123456\r\n\r\n' reply: 'http/1.1 200 ok\r\n' header: date: mon, 10 mar 2014 22:18:00 gmt header: server: apache/2.2.15 (centos) header: x-powered-by: php/5.3.3 header: x-frame-options: sameorigin, sameorigin header: connection: close header: transfer-encoding: chunked header: content-type: application/json; charset=utf-8 200 ok request received vm - dumped logs
2014-03-10 22:18:00 --- debug: headers: http_header object ( [_accept_content:protected] => [_accept_charset:protected] => [_accept_encoding:protected] => [_accept_language:protected] => [storage:arrayobject:private] => array ( [authorization] => bearer 123456 [host] => vm.shibby.com [accept-encoding] => identity [connection] => close ) ) output on server
[root@vm scripts]# ./test.py send: 'get /api/index.php/user http/1.1\r\n host: shibby.com\r\n accept-encoding: identity\r\n authorization: bearer 123456\r\n\r\n' reply: 'http/1.1 400 bad request\r\n' header: date: mon, 10 mar 2014 22:24:55 gmt header: server: apache header: access-control-allow-origin: * header: access-control-allow-headers: authorization header: x-frame-options: sameorigin header: content-length: 37 header: connection: close header: content-type: application/json 400 bad request {"error":"invalid_token"} request received server
2014-03-10 22:33:23 --- debug: headers: http_header object ( [_accept_content:protected] => [_accept_charset:protected] => [_accept_encoding:protected] => [_accept_language:protected] => [storage:arrayobject:private] => array ( [host] => shibby.com [accept-encoding] => identity [connection] => close ) ) as can see, authorization header not received endpoint in question. there no processing happens @ point, logging in constructor of controller.
ok, left important information out. framework using kohana 3.2 , apparently strips authorization header out. had gotten around adding line set environment variable in apache. looks not being run because not accessing end point subdomain is, https://api.shibby.com. anyway, hope helps else.
Comments
Post a Comment