Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ascii codec Error uploading CSV #25

Closed
simonw opened this issue Jul 3, 2022 · 4 comments
Closed

ascii codec Error uploading CSV #25

simonw opened this issue Jul 3, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner

simonw commented Jul 3, 2022

Got this uploading CSV of the Squirrel Census:

{
	"0": {
		"id": "f029f3d9-1d9c-43f7-9eaa-297d3e3e3f9d",
		"filename": "2018_Central_Park_Squirrel_Census_-_Squirrel_Data",
		"bytes_todo": 747760,
		"bytes_done": 7604,
		"rows_done": 30,
		"started": "2022-07-03 20:10:18.452435",
		"completed": null,
		"error": "'ascii' codec can't decode byte 0xe2 in position 170: ordinal not in range(128)"
	}
}
@simonw simonw added the bug Something isn't working label Jul 3, 2022
@simonw
Copy link
Owner Author

simonw commented Jul 3, 2022

@simonw
Copy link
Owner Author

simonw commented Jul 3, 2022

This should have been fixed by the 0.7.1 release but apparently not!

@simonw
Copy link
Owner Author

simonw commented Jul 3, 2022

Hunch: this is because I only use the first 2MB to detect the encoding.

# Use the first 2MB to detect the character encoding
first_bytes = csv.file.read(2048)
csv.file.seek(0)
encoding = detect(first_bytes)["encoding"]
print(encoding)

Also: is ascii a good default encoding to use? If the detection against the first 2MB works maybe I should always use latin-1 just in case?

@simonw
Copy link
Owner Author

simonw commented Jul 3, 2022

Hah, spotted the other problem:

# Use the first 2MB to detect the character encoding
first_bytes = csv.file.read(2048)

The comment says 2MB but 2048 bytes is 2KB!

@simonw simonw closed this as completed in 8f9e6bf Jul 3, 2022
simonw added a commit that referenced this issue Jul 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant