Bug report #11274
File path encoding in "delimitedtext"-Provider
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | - | ||
Category: | Data Provider/Delimited Text | ||
Affected QGIS version: | 2.4.0 | Regression?: | No |
Operating System: | Easy fix?: | No | |
Pull Request or Patch supplied: | No | Resolution: | wontfix |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 19572 |
Description
Hello,
I have a problem with the path encoding of the "delimitedtext"-Provider - as soon as the file path has a special character the following error-message occurs:
"File cannot be opened or delimiter parameters are not valid"
Here is the code:
@uri = u"file:/" + unicode(fileName) + u"?delimiter={0}&xField={1}&yField={2}&crs=epsg:4326&spatialIndex=yes".format(",", "longitude", "latitude")
self.__csvLayer = QgsVectorLayer(uri, "my_csv_layer", "delimitedtext")@
History
#1
Updated by Alexander Bruy over 10 years ago
- Category set to Data Provider/Delimited Text
- Status changed from Open to Feedback
Please be more specific, which "special" characters? Does it also failed when you load this file via QGIS GUI?
#2
Updated by l h_ about 10 years ago
Special character could be an ä - any non english letter...
#3
Updated by l h_ about 10 years ago
It doesn't fail in the GUI... I think the URI-Constructor of the QgsVectorlayer isn't used there. Our plugin is also written in Python, maybe the problem is there?
#4
Updated by Giovanni Manghi about 10 years ago
- Status changed from Feedback to Open
#5
Updated by Minoru Akagi about 10 years ago
You need to convert unicode characters to ascii (URL encoding).
from PyQt4.QtCore import QUrl filename = u"D:\\\\テスト.csv" url = QUrl.fromLocalFile(filename) url.setQueryItems([["delimter", ","], ["key2", "value2"]]) url.toEncoded() # -> PyQt4.QtCore.QByteArray('file:///E:/%E3%83%86%E3%82%B9%E3%83%88.csv?delimter=,&key2=value2') layer = QgsVectorLayer(unicode(url.toEncoded()), "layername", "delimitedtext")
#6
Updated by Minoru Akagi about 10 years ago
last comment has been modified.
wrong: url.toString()
right: unicode(url.toEncoded())
#7
Updated by Alexander Bruy about 9 years ago
- Status changed from Open to Closed
- Resolution set to fixed/implemented
This is not a QGIS bug, plugin should take care about handling non-ASCII characters. Please reopen if necessary
#8
Updated by Alexander Bruy about 9 years ago
- Resolution changed from fixed/implemented to wontfix