Re: [Zope-dev] Accept-Charset hearders causing 500 internal servererror.[correct but not lenient]

2003-02-11 Thread Juan David Ibáñez Palomar

The bug was fixed three weeks ago (branch-1-0), it is
time for a release I guess. Well, only the "strip()",
no "try/except" clause yet.

By the way, Localizer bugs/patches should be sent to
the Localizer mailing list or to the SourceForge tracker
of the LLEU project.


Romain Slootmaekers wrote:


Romain Slootmaekers wrote:
Hi,
below the original post:

it is a bug in Products/Localizer/Accept.py

here's the code to fix it:

#--- code fix starting from line 102 ---


# Get the quality
try:
if len(x) == 2:
quality = x[1]# Get the quality
quality =quality.strip()
quality = quality[2:] # Get the number (remove 
"q=")
quality = float(quality)  # Change it to float
else:
quality = 1.0
except:
quality=1.0
#--- end of code fix ---

I added a strip() and a try/except for other things that can go wrong.

This way Nokia Wap surfers can access your site while Localizer is 
installed.

have fun,

Sloot.

BTW, exceptions that originate here are not caught in the error_log.
this is probably unintended as well.


- original post -

Hi,

We have problems with the Accept-Charset headers that are sent to the 
zope server by some mobile phones:
fi:
'Accept-Charset':'ISO-8859-1, US-ASCII, UTF-8; Q=0.8'

These cause a 500 internal server error. (Error Value: invalid 
literal for float(): =0.8 )

I checked with the HTTP1.1 RFC26160 section 14.2 and the header seems 
valid, but in fact isn't:
there is a space between the semi-colon and the Q char (which 
shouldn't be there acoording to the spec).

So, in principle, this is not a zope server bug, but an inflexibility.

I think the server should be a bit more lenient.
a simple .strip() in the right place should do.

Could you guys fix this?

TIA,

Sloot.




BTW, for completeness, I included a quick test program is included 
below (causes a 500 on my zope 2.6.0) :



#- program illustrating the behavior ---
import httplib, urllib

def sendHTTP():
"""

"""
headers = {'Accept':
   'application/vnd.wap.wmlc, 
application/vnd.wap.wmlscriptc, application/vnd.wap.wbxml, 
image/vnd.wap.wbmp, image/gif, application/*, text/html, 
application/xhtml+xml, application/vnd.wap.wml+xml, text/css',
   'Accept-Charset':'ISO-8859-1, US-ASCII, UTF-8; 
Q=0.8'}#, ISO-10646-UCS-2; Q=0.6'
conn = httplib.HTTPConnection("127.0.0.1:8080")
conn.request("GET", "/mobile/wap/games/",headers=headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
print data

conn.close()

sendHTTP()




___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - http://lists.zope.org/mailman/listinfo/zope-announce
http://lists.zope.org/mailman/listinfo/zope )





___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )




--
J. David Ibáñez, http://www.j-david.net
Software Engineer / Ingénieur Logiciel / Ingeniero de Software



___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Re: Bare "except" dangerous to ZODB? was Re:[Zope-dev] Accept-Charset hearders causing 500 internal servererror.[correct but not lenient]

2003-02-10 Thread Leonardo Rochael Almeida
On Mon, 2003-02-10 at 20:46, Chris McDonough wrote:
> Could this be done by initializing a dictionary at startup keyed on
> thread-id that a ConflictError exception's __init__ could stick a marker
> into, then checking that dictionary at commit time and disallowing the
> commit if the marker still existed? 

+1

And logging a zLOG.ERROR (or maybe even zLOG.PANIC?) level message to
that effect

IMHO, something that blocked commits of ConflictError'ed transactions
should be a requirement in Zope 2.7

I believe that unqualified "except:"'s are the most common cause of
unexplained Zope ZODB corruption.

-- 
Ideas don't stay in some minds very long because they don't like
solitary confinement.


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Accept-Charset hearders causing 500 internal servererror.[correct but not lenient]

2003-02-10 Thread Romain Slootmaekers
Leonardo Rochael Almeida wrote:

On Mon, 2003-02-10 at 10:27, Romain Slootmaekers wrote:


Romain Slootmaekers wrote:
Hi,
below the original post:

it is a bug in Products/Localizer/Accept.py

here's the code to fix it:

#--- code fix starting from line 102 ---


# Get the quality
try:
if len(x) == 2:
quality = x[1]# Get the quality
quality =quality.strip()
quality = quality[2:] # Get the number (remove 
"q=")
quality = float(quality)  # Change it to float
else:
quality = 1.0
except:
quality=1.0
#--- end of code fix ---

I added a strip() and a try/except for other things that can go wrong.



Please, please, please, don't use generic "except:". They can cause ZODB
corruption if they catch ConflictErrors. In the case of the code above,
test for specific errors that "float(quality)" or "x[1]" can raise and
catch those instead.



In general, a generic except is evil.
Here, I seriously don't see how the code inside the try/except can cause 
a conflict error or other serious damage.

In general, general remarks are evil ;)

Sloot.



___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Accept-Charset hearders causing 500 internal servererror.[correct but not lenient]

2003-02-10 Thread Leonardo Rochael Almeida
On Mon, 2003-02-10 at 10:27, Romain Slootmaekers wrote:
> Romain Slootmaekers wrote:
> Hi,
> below the original post:
> 
> it is a bug in Products/Localizer/Accept.py
> 
> here's the code to fix it:
> 
> #--- code fix starting from line 102 ---
> 
> 
> # Get the quality
>  try:
>  if len(x) == 2:
>  quality = x[1]# Get the quality
>  quality =quality.strip()
>  quality = quality[2:] # Get the number (remove 
> "q=")
>  quality = float(quality)  # Change it to float
>  else:
>  quality = 1.0
>  except:
>  quality=1.0
> #--- end of code fix ---
> 
> I added a strip() and a try/except for other things that can go wrong.


Please, please, please, don't use generic "except:". They can cause ZODB
corruption if they catch ConflictErrors. In the case of the code above,
test for specific errors that "float(quality)" or "x[1]" can raise and
catch those instead.

-- 
Ideas don't stay in some minds very long because they don't like
solitary confinement.


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Accept-Charset hearders causing 500 internal servererror.[correct but not lenient]

2003-02-10 Thread Romain Slootmaekers
Romain Slootmaekers wrote:
Hi,
below the original post:

it is a bug in Products/Localizer/Accept.py

here's the code to fix it:

#--- code fix starting from line 102 ---


# Get the quality
try:
if len(x) == 2:
quality = x[1]# Get the quality
quality =quality.strip()
quality = quality[2:] # Get the number (remove 
"q=")
quality = float(quality)  # Change it to float
else:
quality = 1.0
except:
quality=1.0
#--- end of code fix ---

I added a strip() and a try/except for other things that can go wrong.

This way Nokia Wap surfers can access your site while Localizer is 
installed.

have fun,

Sloot.

BTW, exceptions that originate here are not caught in the error_log.
this is probably unintended as well.


- original post -
Hi,

We have problems with the Accept-Charset headers that are sent to the 
zope server by some mobile phones:
fi:
'Accept-Charset':'ISO-8859-1, US-ASCII, UTF-8; Q=0.8'

These cause a 500 internal server error. (Error Value: invalid literal 
for float(): =0.8 )

I checked with the HTTP1.1 RFC26160 section 14.2 and the header seems 
valid, but in fact isn't:
there is a space between the semi-colon and the Q char (which shouldn't 
be there acoording to the spec).

So, in principle, this is not a zope server bug, but an inflexibility.

I think the server should be a bit more lenient.
a simple .strip() in the right place should do.

Could you guys fix this?

TIA,

Sloot.




BTW, for completeness, I included a quick test program is included below 
(causes a 500 on my zope 2.6.0) :



#- program illustrating the behavior ---
import httplib, urllib

def sendHTTP():
"""

"""
headers = {'Accept':
   'application/vnd.wap.wmlc, 
application/vnd.wap.wmlscriptc, application/vnd.wap.wbxml, 
image/vnd.wap.wbmp, image/gif, application/*, text/html, 
application/xhtml+xml, application/vnd.wap.wml+xml, text/css',
   'Accept-Charset':'ISO-8859-1, US-ASCII, UTF-8; Q=0.8'}#, 
ISO-10646-UCS-2; Q=0.6'
conn = httplib.HTTPConnection("127.0.0.1:8080")
conn.request("GET", "/mobile/wap/games/",headers=headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
print data

conn.close()

sendHTTP()




___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - http://lists.zope.org/mailman/listinfo/zope-announce
http://lists.zope.org/mailman/listinfo/zope )





___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Accept-Charset hearders causing 500 internal servererror.[correct but not lenient]

2003-01-30 Thread Florent Guillaume
Ooops, typo in the list name :-)
---

To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED], [EMAIL PROTECTED]
Subject: Re: [Zope-dev] Accept-Charset hearders causing 500 internal server 
error.[correct  but not lenient]
Date: 30 Jan 2003 16:38:20 +0100

That's actually a bug in Localizer. In Accept.py, the Root.parse method
is not flexible enough... I haven't time to fix it right away so someone
else feel free to do it...

Florent

In article <[EMAIL PROTECTED]> you write:
> Hi,
> 
> We have problems with the Accept-Charset headers that are sent to the 
> zope server by some mobile phones:
> fi:
> 'Accept-Charset':'ISO-8859-1, US-ASCII, UTF-8; Q=0.8'
> 
> These cause a 500 internal server error. (Error Value: invalid literal 
> for float(): =0.8 )
> 
> I checked with the HTTP1.1 RFC26160 section 14.2 and the header seems 
> valid, but in fact isn't:
> there is a space between the semi-colon and the Q char (which shouldn't 
> be there acoording to the spec).
> 
> So, in principle, this is not a zope server bug, but an inflexibility.
> 
> I think the server should be a bit more lenient.
> a simple .strip() in the right place should do.
> 
> Could you guys fix this?
> 
> TIA,
> 
> Sloot.
> 
> 
> 
> 
> BTW, for completeness, I included a quick test program is included below 
> (causes a 500 on my zope 2.6.0) :
> 
> 
> 
> #- program illustrating the behavior ---
> import httplib, urllib
> 
> def sendHTTP():
>  """
> 
>  """
>  headers = {'Accept':
> 'application/vnd.wap.wmlc, 
> application/vnd.wap.wmlscriptc, application/vnd.wap.wbxml, 
> image/vnd.wap.wbmp, image/gif, application/*, text/html, 
> application/xhtml+xml, application/vnd.wap.wml+xml, text/css',
> 'Accept-Charset':'ISO-8859-1, US-ASCII, UTF-8; Q=0.8'}#, 
> ISO-10646-UCS-2; Q=0.6'
>  conn = httplib.HTTPConnection("127.0.0.1:8080")
>  conn.request("GET", "/mobile/wap/games/",headers=headers)
>  response = conn.getresponse()
>  print response.status, response.reason
>  data = response.read()
>  print data
> 
>  conn.close()
> 
> sendHTTP()

-- 
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87  http://nuxeo.com  mailto:[EMAIL PROTECTED]


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )