clonly / python4delphi

Automatically exported from code.google.com/p/python4delphi
0 stars 0 forks source link

AttributeError: NoneType #25

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1. create file webserver.py:

from wsgiref.simple_server import make_server

def app(environ, start_response):
    status = '200 OK' # HTTP Status
    headers = [('Content-type', 'text/plain; charset=utf-8')] # HTTP Headers
    start_response(status, headers)

    # The returned object is going to be printed
    return [b'Hello world!']

def start():
    server = make_server('127.0.0.1', 8070, app)

    server.serve_forever()

2. in Delphi use next to call script:

  fModule: variant;
  PE: TPythonEngine;

...

  PE := TPythoneEngine.Create;

...

  with GetPythonEngine do begin
    fModule := import('webserver');
    fModule.start();
  end;

3. in browser type 'http://localhost:8070', as expected message 'Hello World!' 
appears, but then Delphi rise an error "AttributeError: NoneType object has no 
attribute write"

Windows 7 Pro 64bit, Delphi 2006, Python 3.3 32bit

Original issue reported on code.google.com by atihon...@tialys.com on 4 Sep 2013 at 4:40

GoogleCodeExporter commented 9 years ago
Finally I found solution myself, it was an I/O problem. I added logging module 
to my script to trace an error and it rise when simple_server try to log 
request. I did't create any output stream so exception rise in my app and not 
in pyscripter.
Setting "Redirect IO" to False and "UseWindowsConsole" to True and my error 
gone.

Original comment by atihon...@tialys.com on 4 Sep 2013 at 9:05

GoogleCodeExporter commented 9 years ago

Original comment by pyscripter on 28 Mar 2015 at 1:57