0

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)

1 Answer 1

1

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.