I have directive to display player image. I send player id to small Python script to check if image with such id exists via ajax call. If image exists, I need to return its name.
I succeeded in sending id from fronted to script and finding the image name. The problem is that I am failing to return the file name correctly. I am getting error:
HTTP Error 502.2 - Bad Gateway The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "HCP_23108_SmithKen.png ".
If I add headers, I am still getting error:
HTTP Error 502.2 - Bad Gateway The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "Content-type: text/html; charset=utf-8 HCP_23108_SmithKen.png ".
I did enabled cgi in Handler Mappings of IIS7 by following Python on IIS: how?
My question is how to perform Ajax GET request correctly without any Python frameworks? Thanks
Directives:
myDirectives.directive('headshot', function ($http) {
return {
restrict: 'AE',
scope: {
lastProID: '@lastproid'
},
template: '<img ng-src="{{proImg}}" class="headshot">',
link: function (scope, element, attrs) {
//scope.id = scope.lastProID;
attrs.$observe('lastproid', function (id) {
scope.id = id;
var src = 'img/bios/nophoto.png';
scope.proImg = (src);
var url = 'bioPhoto/bioPhoto.py';
$http.get(
url,
{
params: {'id': scope.id}
})
.success(function (data) {
var src = 'img/bios/' + data;
scope.proImg = (src);
})
.error(function (error) {
});
});
}
};
});
bioPhoto.py script:
import fnmatch
import os
rootPath = './img/bios/'
query_string=os.environ["QUERY_STRING"]
id=query_string.split("id=",1)[1]
id=id.strip()
pattern = "*" + id + "*"
print ('Content-type: text/html; charset=utf-8')
for root, dirs, files in os.walk(rootPath):
for filename in fnmatch.filter(files, pattern):
filename=filename.strip()
print(filename)
You need a blank line after your headers. (See: http://www.oreilly.com/openbook/cgi/ch03_02.html )
Try this:
print ('Content-type: text/html; charset=utf-8\n\n')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.