[Pulp-list] unicode strings in our request URLs
Mike McCune
mmccune at redhat.com
Fri Oct 29 18:31:33 UTC 2010
For those that remember the baffling errors you sometimes have to debug
where Apache barfs with:
[Fri Oct 29 11:09:46 2010] [error] [client 127.0.0.1] Invalid method in
request P
in your ssl_error_log ...
and your pulp client bombs with:
Traceback (most recent call last):
File "/usr/bin/pulp-admin", line 7, in <module>
execfile(__file__)
...
File "/usr/lib64/python2.6/json/decoder.py", line 338, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
leaving you with no real way to figure out what is going on other than
to bang your head against the wall and hope that you remembered that
according to RFC 1738:
http://www.faqs.org/rfcs/rfc1738.html
"URLs are written only with the graphic printable characters of the
US-ASCII coded character set."
and
" Thus, only alphanumerics, the special characters "$-_.+!*'(),", and
reserved characters used for their reserved purposes may be used
unencoded within a URL."
To fix this we have done this in our code:
connection.py: method = "/consumers/%s/" % str(id)
connection.py: method = "/consumers/%s/packages/" % str(id)
connection.py: method = "/consumers/%s/certificate/" % str(id)
connection.py: method = "/consumers/%s/keyvalues/" % str(id)
connection.py: method = "/consumergroups/%s/" % str(id)
connection.py: method = "/users/%s/" % str(login)
note the str() wrapping the param.
Instead of forcing our developers to remember todo this why don't we
just do the following in connection.py:
diff --git a/src/pulp/client/connection.py b/src/pulp/client/connection.py
index 0067dbb..6d4b75c 100644
--- a/src/pulp/client/connection.py
+++ b/src/pulp/client/connection.py
@@ -106,7 +106,9 @@ class Restlib(object):
self.key_file = key_file
def _request(self, request_type, method, info=None):
- handler = method
+ # Convert the method (path) into a string so we dont
+ # have any unicode characters in the URL
+ handler = str(method)
if not handler.startswith(self.apihandler):
#handler = self.apihandler + handler
handler = '/'.join((self.apihandler, handler))
Any objections?
Mike
More information about the Pulp-list
mailing list