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

Unknown Image Data Format Error when opening Part Details #425

Closed
markusdd opened this issue Mar 5, 2024 · 4 comments · Fixed by #426
Closed

Unknown Image Data Format Error when opening Part Details #425

markusdd opened this issue Mar 5, 2024 · 4 comments · Fixed by #426
Assignees

Comments

@markusdd
Copy link
Contributor

markusdd commented Mar 5, 2024

Latest greatest KiCAD 8 and latest version of plugin.

I'm facing this when using the Part Details dialog.

grafik

I am unsure at this point if this has anything to do with KiCAD8 or if JLCPCB has played us here.

Suspicious code location where I think it goes wrong (the error must be form wxwidgets because it's nowhere in the plugin codebase):

def get_scaled_bitmap(self, url, width, height):

Any background info on this @Bouni? Happy to work on a possible fix, but I do not know what image format these were originally expected in and what wxwidgets can support out of the box.

@markusdd
Copy link
Contributor Author

markusdd commented Mar 5, 2024

Ok, checked the code further and when using the shopcart URL used to get the data for this dialog, I see no immidiate issue, the 96x96 replacement to 900x900 should still be valid.

grafik

With this, using imageList, we actually could make the parts page even cooler by making it possible to flip through all big images, but that is more a feature request.

The Image format is jpg. Is that what we expect?
Seems pretty standard, a bit confused why this would fail now.

@markusdd
Copy link
Contributor Author

markusdd commented Mar 5, 2024

Ok, that is wild.
I enforced interpreting the byte stream as a JPEG instead of auto detection:

    def get_scaled_bitmap(self, url, width, height):
        """Download a picture from a URL and convert it into a wx Bitmap"""
        content = requests.get(url, timeout=10).content
        self.logger.info("Fetching Image %s", str(url))
        io_bytes = io.BytesIO(content)
        self.logger.info("Image Byte Content %s", str(io_bytes))
        image = wx.Image(io_bytes, type=wx.BITMAP_TYPE_JPEG)
        image = image.Scale(width, height, wx.IMAGE_QUALITY_HIGH)
        result = wx.Bitmap(image)
        return result

and then I get this:

grafik

But the URL is 100% positivly pointing to a jpg:

https://assets.lcsc.com/images/lcsc/900x900/20221227_FH--Guangdong-Fenghua-Advanced-Tech-0805B152K500NT_C1717_front.jpg

I'm a bit baffled. Any ideas?

EDIT: The header of the downloaded file definetly also advertises it as jpeg and no ther image viewer is complaining. I'm more thinking this is an issue with the Byte-IO-Stream.
grafik

@markusdd
Copy link
Contributor Author

markusdd commented Mar 5, 2024

ok haha: I think we have our issue:

2024.03.05 14:45:49 - INFO - get_scaled_bitmap -  Fetching Image https://assets.lcsc.com/images/lcsc/900x900/20221227_FH--Guangdong-Fenghua-Advanced-Tech-0805B152K500NT_C1717_front.jpg
2024.03.05 14:45:49 - INFO - get_scaled_bitmap -  Image Byte Content b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">\n<TITLE>ERROR: The request could not be satisfied</TITLE>\n</HEAD><BODY>\n<H1>403 ERROR</H1>\n<H2>The request could not be satisfied.</H2>\n<HR noshade size="1px">\nRequest blocked.\nWe can\'t connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.\n<BR clear="all">\nIf you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.\n<BR clear="all">\n<HR noshade size="1px">\n<PRE>\nGenerated by cloudfront (CloudFront)\nRequest ID: Up1AOdk5pjWucz0rRMwp0pflI493h8hbj6tWAevIERNzZJNcp5j95g==\n</PRE>\n<ADDRESS>\n</ADDRESS>\n</BODY></HTML>'

@markusdd
Copy link
Contributor Author

markusdd commented Mar 5, 2024

Ok, so they are filtering for Python User Agent.
Then let's pretend we are a browser:

headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36"
        }
        content = requests.get(url, headers=headers, timeout=10).content

And it works :D
grafik

I will submit a PR to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants