From e4c3483ecf496b7637d1e9fd3b0eb9ace94a09d2 Mon Sep 17 00:00:00 2001 From: Sven Schwermer Date: Thu, 11 Apr 2024 12:10:29 +0200 Subject: recipetool: Handle unclean response in go resolver It appears that some go modules repond with a 404 error when trying to resolve them dynamically. The response body may still contain the go-import meta tag. An example for such behaviour is gonum.org/v1/gonum. (From OE-Core rev: 8f2e14ab6562a9a68819a960c66a258ea9dbe246) Signed-off-by: Sven Schwermer Signed-off-by: Alexandre Belloni Signed-off-by: Richard Purdie --- scripts/lib/recipetool/create_go.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'scripts/lib') diff --git a/scripts/lib/recipetool/create_go.py b/scripts/lib/recipetool/create_go.py index c560831442..0fb7115e26 100644 --- a/scripts/lib/recipetool/create_go.py +++ b/scripts/lib/recipetool/create_go.py @@ -16,7 +16,7 @@ from html.parser import HTMLParser from recipetool.create import RecipeHandler, handle_license_vars from recipetool.create import guess_license, tidy_licenses, fixup_license from recipetool.create import determine_from_url -from urllib.error import URLError +from urllib.error import URLError, HTTPError import bb.utils import json @@ -251,15 +251,18 @@ class GoRecipeHandler(RecipeHandler): req = urllib.request.Request(url) try: - resp = urllib.request.urlopen(req) - + body = urllib.request.urlopen(req).read() + except HTTPError as http_err: + logger.warning( + "Unclean status when fetching page from [%s]: %s", url, str(http_err)) + body = http_err.fp.read() except URLError as url_err: logger.warning( "Failed to fetch page from [%s]: %s", url, str(url_err)) return None parser = GoImportHTMLParser() - parser.feed(resp.read().decode('utf-8')) + parser.feed(body.decode('utf-8')) parser.close() return GoImport(parser.import_prefix, parser.vcs, parser.repourl, None) -- cgit v1.2.3-54-g00ecf