Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Mineral Catalog (tech degree) URL/filename decode?

So after submitting my project, it was kicked back for an issue with properly loading ALL images. The images it did load all have 1 thing in common. They did not have %2C in the filename.

So the recommended solution in the review notes was to:

The only reason you got "Needs Work" here is because of the image issues you mentioned. Check this out for a hint on how to fix it: Stack Overflow

But this solution I tried every which way and does work or I am not understanding its application correctly.

Here is an screenshot I took of what is happening. I tried to capture each scenario and filenames its looking for

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

So if I go into my images folder, make a copy of a file that has the %2C encoding (comma).

I replace those encodings with a ,. It will load it fine.

Example Image

Is this some issue between filesystems? I am sure these files were created and zipped on a Mac and I am unzipping and reading them on Windows. My filenames have the encoded string Django recognizes them in a URL and properly decodes the %2C out of the URL. But they exist on the filesystem with the %2C so It can never find it?

Makes my brain spin. :-|

2 Answers

Tatiana Vasilevskaya
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tatiana Vasilevskaya
Python Web Development Techdegree Graduate 28,600 Points

This problem has already been discussed in Python Techdegree Slack. Kenneth said basically the same thing as you've mentioned. The problem is that the %25, etc is getting URL encoded when Django requests it (as it should) but it's not URL encoded on the disk. So images should be renamed appropriately first as you and other students did. Actually, they were supposed to provide correctly named images in the download zip.

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Oh great! I actually don't have the Slack channel included in my tech degree or I would of seen this.

Though I am glad this was already discussed. That is probably why when I went back to resubmit my project it was already checked off sometime after I posted.

I am going to check you off as Best Answer though since its basically relayed from the instructor. And Im not a fan of marking myself as Best Answer when it was my question in the first place.

Thanks for relaying.

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

So I noticed that a few other students that have worked on the Minerals Catalog through Github uploaded their images but their filenames are the UTF8 decoded filenames, whereas mine unpacked with the encoded version.

My solution: Renamed the filenames with their proper UTF8 encoding from their %xx encoded string.

But because there are 868 images, I instead wrote a Python script that basically used these imports to loop through the entire images folder to rename every filename to the proper UTF8 name. My Django server now recognizes all pictures in that folder with my original code. ( it took <2 seconds to run ) woohoo!

import os
from urllib import parse

# using os.path.join and os.path.rename

#using parse.unquote(file)  --- gives back UTF8 filename