I'm new to both zope and python, so I hope you'll forgive my ignorance. I'm writing a simple file upload web page. I've got it working most of the time; however when file names have certain characters in them I get errors like this: Zope Error Zope has encountered an error while publishing this resource. Error Type: Bad Request Error Value: The id "[X=X].foo" contains characters illegal in URLs. The code generating this error is as follows: origfilename=file.filename id=origfilename[max(string.rfind(origfilename, '/'), string.rfind(origfilename, '\\'), string.rfind(origfilename, ':'), )+1:] context.DemoArchive.manage_addFile(id,file, demo_title) I thought that using quote_url_plus would solve this, so I changed to: origfilename=file.filename id=origfilename[max(string.rfind(origfilename, '/'), string.rfind(origfilename, '\\'), string.rfind(origfilename, ':'), )+1:] id=url_quote_plus(id) context.DemoArchive.manage_addFile(id,file, demo_title) However I get the same error with the new string: The id "%5BX%3DX%5D.foo" contains characters illegal in URLs Can anyone tell me how to fix this please? TIA.
Paul Rudin writes:
I'm writing a simple file upload web page. I've got it working most of the time; however when file names have certain characters in them I get errors like this:
Zope Error Zope has encountered an error while publishing this resource.
Error Type: Bad Request Error Value: The id "[X=X].foo" contains characters illegal in URLs. Zope restricts ids to contain only characters legal in URLs (and space).
One solution would be that you do not use the filename as id but put the filename in the title and use an artificial id (e.g. derived from "ZopeTime"). I have another solution, but it is not easy to use. You need to be quite proficient with Python: An international ObjectManager that supports almost arbitrary id's. With it, you can build custom folders that will not refuse your strange ids. You could also steal the idea and use it in a so called monkey patch. This, too, requires proficiency with Python and dynamic Zope modifications. Dieter
Dieter Maurer <dieter@handshake.de> writes:
Paul Rudin writes:
I'm writing a simple file upload web page. I've got it working most of the time; however when file names have certain characters in them I get errors like this:
Zope Error Zope has encountered an error while publishing this resource.
Error Type: Bad Request Error Value: The id "[X=X].foo" contains characters illegal in URLs.
Zope restricts ids to contain only characters legal in URLs (and space).
Ok, thanks. So why does using the result of quote_url_plus as an id also fail? Surely such a string should necessarily consist of url-legal characters?
Paul Rudin writes:
Dieter Maurer <dieter@handshake.de> writes: .... Zope restricts ids to contain only characters legal in URLs (and space).
Ok, thanks. So why does using the result of quote_url_plus as an id also fail? Surely such a string should necessarily consist of url-legal characters? The '%' is illegal in URLs (unless it is quoted). Zope is too stupid to recognize url encoding and complains about the '%'.
In my opinion, it is time to get rid of the URL character restriction. It will be a bit difficult to find all places in Zope's code where omitting the restriction will require an explicit quoting, but it will be worth the effort. Maybe, you want to write a proposal? Dieter
Paul Rudin <paul.rudin@ntlworld.com> writes:
I'm new to both zope and python, so I hope you'll forgive my ignorance.
I'm writing a simple file upload web page. I've got it working most of the time; however when file names have certain characters in them I get errors like this:
Zope Error Zope has encountered an error while publishing this resource.
Error Type: Bad Request Error Value: The id "[X=X].foo" contains characters illegal in URLs.
On a related note - if you use manage_addFile with a file without supplying an id you get the same error. Shouldn't the code that generates the id from the filename cope with ensuring that you get a valid id?
participants (2)
-
Dieter Maurer -
Paul Rudin