[issue33663] Web.py wsgiserver3.py raises TypeError when CSS file is not found
Jean-Marc Le Peuvedic added the comment: The exception is raised in the start_response function provided by web.py's WSGIGateway class in wsgiserver3.py:1997. # According to PEP , when using Python 3, the response status # and headers must be bytes masquerading as unicode; that is, they # must be of type "str" but are restricted to code points in the # "latin-1" set. Therefore, header values must be strings whenever start_response is called. WSGI servers must accumulate headers in some data structure and must call the supplied "start_response" function, when they have gathered all the headers and converted all the values to strings. The fault I observed is not strictly speaking caused by a bug in Python lib "server.py". Rather, it is a component interaction failure caused by inadequately defined semantics. The interaction between web.py and server.py is quite complex, and no component is faulty when considered alone. I explain: Response and headers management in server.py is handled by 3 methods of class BaseHTTPRequestHandler: - send_response : puts response in buffer - send_header : converts to string and adds to buffer ("%s: %s\r\n" % (keyword, value)).encode('latin-1', 'strict')) - end_headers : flushes buffer to socket This implementation is correct even if send_header is called with an int value. Now, web.py's application.py defines a "wsgi(env, start_resp)" function, which gets plugged into the CherryPy WSGI HTTP server. The server is an instance of class wsgiserver.CherryPyWSGIServer created in httpserver.py:169 (digging deeper, actually at line 195). This server is implemented as a HTTPServer configured to use gateways of type class WSGIGateway_10 to handle requests. A gateway is basically an instance of class initialized with a HTTPRequest instance, that has a "respond" method. Of course the WSGIGateway implements "respond" as described in the WSGI standard: it calls the WSGI-compliant web app, which is a function(environ, start_response(status, headers)) returning an iterator (for chunked HTTP responses). The start_response function provided by class WSGIGateway is where the failure occurs. When the application calls web.py's app.run(), the function runwsgi in web.py's wsgi.py get called. This function determines if it gets request via CGI or directly. In my case it starts a HTTP server using web.py's runsimple function (file httpserver.py:158). This function never returns, and runs the CherryPyWSGIServer, but it first wraps the wsgi function in two WGSI Middleware callables. Both are defined in web.py's httpserver.py file. The interesting one is StaticMiddleWare (line 281). Its role, is to hijack URLs starting with /static, as is the case with my missing CSS file. In order to serve those static resources quickly, its implementation uses StaticApp (a WSGI function serving static stuff, defined line 225), which extends Python's SimpleHTTPRequestHandler. That's where to two libraries connect. StaticApp changes the way headers are processed using overloaded methods for send_response, send_header and end_headers. This means that, when StaticApp calls SimpleHTTPRequestHandler.send_head() to send the HEAD part of the response, the headers are managed using the overloaded methods. When send_head() finds out that my CSS file does not exist and calls send_error() a Content-Length header gets written, but it is not converted to string, because the overloaded implementation just stores the header name and value in a list as they come. When it has finished gathering headers using Python's send_head(), it immediately calls start_response provided by WSGIGateway, where the failure occurs. The bug in Python is not strictly that send_header gets called with an int in send_error. Rather, it is a documentation bug which fails to mention that send_header/end_headers MUST CONVERT TO STRING and ENCODE IN LATIN-1. Therefore the correction I proposed is still invalid, because the combination of web.py and server.py after the correction, still does not properly encode the headers. As a conclusion I would say that: - In Python lib, the bug is a documentation bug, where documentation fails to indicate that send_headers and/or end_headers can receive header names or values which are not strings and not encoded in strict latin-1, and that it is their responsibility to do so. - In Web.py because the implementation of the overloaded methods fails to properly encode the headers. Of course, changing int to str does no harm and makes everything more resilient, but does not fix the underlying bug. -- ___ Python tracker <https://bugs.python.org/issue33663> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33663] Web.py wsgiserver3.py raises TypeError when CSS file is not found
New submission from Jean-Marc Le Peuvedic <lepeuve...@gmail.com>: When running the built-in web server of web.py, the following error messages appear when the HTTP client fetches a non existing CSS file: TypeError('WSGI response header value 469 is not of type str.',) Traceback (most recent call last): File "/home/jm/miniconda3/envs/REST/lib/python3.6/site-packages/web/wsgiserver/wsgiserver3.py", line 1089, in communicate req.respond() File "/home/jm/miniconda3/envs/REST/lib/python3.6/site-packages/web/wsgiserver/wsgiserver3.py", line 877, in respond self.server.gateway(self).respond() File "/home/jm/miniconda3/envs/REST/lib/python3.6/site-packages/web/wsgiserver/wsgiserver3.py", line 1982, in respond for chunk in response: File "/home/jm/miniconda3/envs/REST/lib/python3.6/site-packages/web/httpserver.py", line 267, in __iter__ self.start_response(self.status, self.headers) File "/home/jm/miniconda3/envs/REST/lib/python3.6/site-packages/web/httpserver.py", line 320, in xstart_response out = start_response(status, response_headers, *args) File "/home/jm/miniconda3/envs/REST/lib/python3.6/site-packages/web/wsgiserver/wsgiserver3.py", line 2029, in start_response "WSGI response header value %r is not of type str." % v) TypeError: WSGI response header value 469 is not of type str. The faulty header is added by Python library, http/server.py. Error added in version 3.4 according to comments. Lines 467-471 in the attached file: body = content.encode('UTF-8', 'replace') self.send_header("Content-Type", self.error_content_type) self.send_header('Content-Length', int(len(body))) self.end_headers() The value for 'Content-Length' is passed as an 'int', but only a 'str' is acceptable. In the latest revision of 'server.py', the same code appears line 453. A possible correction is : body = content.encode('UTF-8', 'replace') self.send_header("Content-Type", self.error_content_type) self.send_header('Content-Length', str(int(len(body self.end_headers() -- components: Library (Lib) files: server.py messages: 317813 nosy: jmlp priority: normal severity: normal status: open title: Web.py wsgiserver3.py raises TypeError when CSS file is not found type: behavior versions: Python 3.6 Added file: https://bugs.python.org/file47616/server.py ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33663> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy saff...@gmail.com added the comment: You are suggesting something like this, I suppose? --- a/Lib/netrc.py +++ b/Lib/netrc.py @@ -105,8 +105,8 @@ class netrc: def __repr__(self): Dump the class data in the format of a .netrc file. rep = -for host in self.allhosts.keys(): -for attrs in self.allhosts[host]: +for (host, attrlist) in self.allhosts.items(): +for attrs in attrlist: rep = rep + machine + host + \n\tlogin + repr(attrs[0]) + \n if attrs[1]: rep = rep + account + repr(attrs[1]) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11416 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy saff...@gmail.com added the comment: Patch slightly updated after Eric's comments. -- Added file: http://bugs.python.org/file22193/netrc.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11416 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy saff...@gmail.com added the comment: Patch formatting changed to be more review-friendly (looks like MQ-style patch isn't?), otherwise same as 2011-05-30 16:14. -- Added file: http://bugs.python.org/file22194/netrc.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11416 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy saff...@gmail.com added the comment: Eric: yes I can look into the asserts, but note I generated and tested my patch from a checkout of 2.6 (see my first report), so maybe that's why I didn't see any warning. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11416 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy saff...@gmail.com added the comment: Here is a patch against 2.7. -- Added file: http://bugs.python.org/file22195/netrc.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11416 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy saff...@gmail.com added the comment: Additional patch for docstrings and documentation. Applies on top of previous patch. -- Added file: http://bugs.python.org/file22204/netrc-doc.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11416 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Changes by Jean-Marc Saffroy saff...@gmail.com: Removed file: http://bugs.python.org/file21443/netrc.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11416 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy saff...@gmail.com added the comment: Ping? A patch is available for review. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11416 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy saff...@gmail.com added the comment: So I finally cooked a little patch for netrc.py in python 2.6. The patch extends netrc.authenticators() with an extra parameter to select a login name, but otherwise the behaviour remains the same (still returns the last entry for a given host). Lightly tested, works for me. -- keywords: +patch Added file: http://bugs.python.org/file21443/netrc.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11416 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11416] netrc module does not handle multiple entries for a single host
Jean-Marc Saffroy saff...@gmail.com added the comment: Good that you mentioned the official tests, they let me see that netrc.hosts is actually part of the API, and my first patch broke it. Here is an updated patch, with extra tests. -- Added file: http://bugs.python.org/file21444/netrc.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11416 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1461] 0**0 should raise an error
Changes by Jean-Marc Gillet: -- nosy: jmgillet severity: minor status: open title: 0**0 should raise an error type: behavior __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1461 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1461] 0**0 should raise an error
New submission from Jean-Marc Gillet: The result is actually undefined, as x**0 gives 1 and 0**x gives 0. Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. 1**0 1 0**1 0 0**0 1 -- components: +Interpreter Core versions: +Python 2.5 __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1461 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1461] 0**0 should raise an error
Jean-Marc Gillet added the comment: See http://en.wikipedia.org/wiki/Exponentiation Zero to the zero power. There are pros and cons of 0**0==1 so if you mark this one as wontfix I promise not to bother you again :-) __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1461 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: py-ldap question
and this set option ? ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,ldap.OPT_X_TLS_NEVER) HTH Laszlo Nagy a écrit : By the way, I already tried the set_option function, but I still get the same error. snip import ldap import local ldap.set_option(ldap.OPT_X_TLS_ALLOW,1) ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,0) ldap.set_option(ldap.OPT_X_TLS_CERTFILE,local.LDAP_CACERTFILE) ldap.set_option(ldap.OPT_X_TLS_CACERTFILE,local.LDAP_CACERTFILE) def getnewconnection(logindc,password): conn = ldap.initialize(local.LDAP_SERVER_URL) conn.simple_bind_s(logindc,password) return conn if __name__ == '__main__': conn = getnewconnection(local.LDAP_MANAGER_DC,local.LDAP_MANAGER_PWD) print conn /snip -- http://mail.python.org/mailman/listinfo/python-list
Re: textwidget.tag_bind(name, Any-KeyPress, self.donothing) not working
but you don't want to use the state=DISABLED option because it gray's out the field showing people that it is not available for editing, right? -- http://mail.python.org/mailman/listinfo/python-list
Re: textwidget.tag_bind(name, Any-KeyPress, self.donothing) not working
Sorry, kinda wrote over your intentions... -- http://mail.python.org/mailman/listinfo/python-list
Re: textwidget.tag_bind(name, Any-KeyPress, self.donothing) not working
To make amends, I tried my own search and came up with this (that you might already have...): http://groups.google.com/group/comp.lang.python/browse_thread/thread/1384f49c35ffba9b/5928092247429e9a%235928092247429e9a?sa=Xoi=groupsrstart=1num=3 Maybe you'll understand it better than me :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs Ruby
I'd believe that would be Lua, but then again what is common to one might not be to another ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs Ruby
As you see, pythonistas are a nice humourous bunch... But to help a bit more in your balancing act you might take a look at: http://blog.ianbicking.org/ruby-python-power.html It's rather nice, and commented. -- http://mail.python.org/mailman/listinfo/python-list
Re: python classes taught
Cegep du Vieux Montreal (technical college level), uses Python for CGI in web developement class. ...At least when I give this course ;-) Jean-Marc -- http://mail.python.org/mailman/listinfo/python-list
Re: SOAP and XMLRPC
why isn't this good? http://www.enappsys.com/backend.jsp Seems to be what you're looking for... (second entry of a googled 'xml-rpc visual basic' search!) JM PS Tell us why the refered *.dll don't do, so I won't refer to it again if it's of no value. -- http://mail.python.org/mailman/listinfo/python-list
Re: seeking Python developers
What level? and is geography important? JM -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use more than 1 __init__ constructor in a class ?
Singletoned wrote: Rocco Moretti wrote: Steven D'Aprano wrote: snip That's the joys of a mostly self-taught programming knowledge: you miss out on all the buzzwords. Being mostly self taught myself, I have a tendancy to use infrequently encountered terms in related but technically inappropriate contexts, confusing the better informed people I deal with. ;-) Indeed. I find I use even more buzzwords because I can just make up as many as I want. This thread 'branch' (humm, is this an appropriate term for the last few quotes, going to Steven's?) is soothing in reminding us we are not alone. That there is a sort of distributed 'Alma Mater' of the 'Teach-It-Yourself School of Computing', producing a virtual FOAF group (Is FOAF, Friend Of A Friend or Flock Of A Feather?) jm -- http://mail.python.org/mailman/listinfo/python-list
Thanks for PIL (and other stuff)
I was just reading on daily-python that PIL is 10 years old... So I wish it and its author(s) a good day, week, month, year and more! Really! Jean-Marc PS If I knew that Python had a anniversary date, I'd also write to thanks our BDFL (and authors)! But no such luck, so I'm restaining myself! ;-)) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python as CGI on IIS and Windows 2003 Server
[EMAIL PROTECTED] wrote: jean-marc schrieb: Some bits are coming back to me: the problems stemmed from adresses - getting the root of IIS was different so accessing files didn't work the same way. thanks for that. you are right, IIS versions are different. Wich kind of adresses do you mean, http-adresses or paths in file systems to root of IIS or to pythonscripts below IIS' root? Unfortunately I couldn't find a way to solve the problem. regards Lothar I think it was due to the way of getting a reference to the IIS's root - I think that all adresses in html (wheter from static documents or those generated by python) need to use relative adresses (double dot slash, or dot slash type of adresses). If it still doesn't work maybe posting some culprit code could help figure it out...! Jean-Marc May -- http://mail.python.org/mailman/listinfo/python-list
Re: Python as CGI on IIS and Windows 2003 Server
[EMAIL PROTECTED] wrote: Hi, My python scripts are running as cgi scripts on an IIS on Windows XP. I have to distribute it to IIS on Windows 2003 Server. ... Is there any difference for python as CGI on IIS between Windows XP prof. and Windows 2003 Server? ... Yes there is a difference! I had this problem last year (developing on Win XP Pro and delivering on IIS Server), I'll try to lookup the solution, but it might be difficult (it's kind of a thing you do once and forget about later.) Jean-Marc -- http://mail.python.org/mailman/listinfo/python-list
Re: Python as CGI on IIS and Windows 2003 Server
Some bits are coming back to me: the problems stemmed from adresses - getting the root of IIS was different so accessing files didn't work the same way. I'm also quite positive that my desktop (developement version) was IIS 5.1 which comes with XP Pro compared to 6.0 for IIS Server. I changed the way I was dealing with file adresses. Maybe there is a hint of direction for your own investigation... Jean-Marc -- http://mail.python.org/mailman/listinfo/python-list
Re: write to the same file from multiple processes at the same time?
Sorry, why is the temp file solution 'stupid'?, (not aesthetic-pythonistic???) - it looks OK: simple and direct, and certainly less 'heavy' than any db stuff (even embedded) And collating in a 'official log file' can be done periodically by another process, on a time-scale that is 'useful' if not instantaneous... Just trying to understand here... JMD -- http://mail.python.org/mailman/listinfo/python-list
God damn error 666 (Tkinter in PythonWin)
Hello, No I'm not angry - but my machine seems to be :-| A pop-up dialog appears while trying to close the main PythonWin window that has that error 'God damn error 666' - I can close this and then the machine is ok BUT bye bye PythonWin... This occurs after a progression of windows (small 'w' for the frame on screen, not the OS) related problems occur within the PythonWin environment, and these problems follow after trying to debug Tkinter apps from within PythonWin, which I had read was problematic, causing all sorts of problem BUT never thinking it was the kind that couldn't get fixed by a shut-down and reboot type of memory cleansing... Even uninstalling all of Python and related stuff and re-installing them does not make this better. The progression of the sickness as best as I can remember is like this: First, the debugger stalls and fails to permit correct exit, Secong PythonWin seems fine (editor that is) but can't open any other windows (browsers , pdf files etc) at the same time, Third, Python's windows don't appear to fill out (documentation, for example) Fourth, I can't even open Pythonwin itself correctly, window open without menus, or such stuff... I think the nasty dialog referred to above appears between the third and fourth events... Sorry, this was not made to be a scientific test, so I can't be morfe precise, it just happened to me twice recently because I'm on a 10-15 K lines of program that uses Tkinter for the first time. Mark Hammond doesn't seem to know where this comes from; thinks it might be Tk related thing so I'm posting here in case it means anything to anyone, (My environment: ToshibaA70, Python 2.3.5, pyWin 203 (from ActiveState), under Windows XP Pro SP2) Hoping this is not CHTULHU telling to do something else with my life ;-) Jean-Marc -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing and namespace visibility
Merci Bruno, ( and also to Fredrik ) So I think I understand correctly, if I say that: each modulkes requires its own set of reference to whatever objects it needs to speak. The interpreter wil see not to create extra copies of the compiled code if many modules import the same modules but will make them all point to the one already existing (in this program's execution). Practically, it means every module import whatever it needs - be careful with recursive imports - keep things tidy by using the 'import suchModule' (and use dotted name chains to reach whatever is needed). Again thank you, JM PS Nice weather in Bordeaux ? I've been there once... (when I was young (sigh)) -- http://mail.python.org/mailman/listinfo/python-list
Importing and namespace visibility
As an application programmer, I'm not well versed in the material aspects of computing (memory, cpu, bus and all). My understanding of imports in Python is such: the __main__ program is the center piece which holds the programs reference: globals, functions, classes, modules etc. The objects of this file (functions and classes) are directly accessible; 'import suchModule' s objects are attainable through the *qualified name* (module.function); the 'from suchModule import *' the objects are directly attainable. A recent msg from F. Lundh http://groups.google.ca/group/comp.lang.python/browse_frm/thread/f9bf9734fa19eee9/8a51ab24748251d8?q=rnum=12hl=en#8a51ab24748251d8 suggested being careful with recursive importing... BUT, of all this I thought that if you import module1, then module2 (into __main__), objects from module1 would be available to objects of module2 which came (into memory space) after module1 was loaded. This does not seem to be the case, and module2 requires an 'import module1' statement in its own file to see this last module's objects. This is not the recursive situation that was a pitfall Fredrik was evoking. What am I missing here??? The reason I'm asking is to setup team development, using Tkinter, where different people will be programming diverse sections to be 'packed' into the main interface... Thanks for any help in understanding what is happening in this situation, JMD -- http://mail.python.org/mailman/listinfo/python-list
PythonWin + Tkinter = broken relation with WindowsXP !?!?!
I read that Tkinter and Python IDEs (PythonWin and Idle at least) makes for a bad mix in execution mode because they're fighting for the event loop, but this mode is usefull to use the debugger. But to the point of breaking something elsewhere than in memory ??? (Shutting down and rebooting the computer doesn't resolve the problems... PythonWin becomes impossible to use if another window is open (pdf files, winAmp music, browser et al...) is this documented somewhere??? It's been happening quite a few times to me (real bummer!). NOTE: This situation seems to appear slowly... Not like a works or doesn't work situation but rather that corruption is progressive. This is a complete mystery to me Thanks in advance, JMD Python 2.3.5, WinXP Pro SP2 I've started using Python Scripter, which seems less problematic (at this point) -- http://mail.python.org/mailman/listinfo/python-list