Last active
May 17, 2023 09:57
-
-
Save ochilab/261c6dc0178c5f7b5fe6ae4267c6041d to your computer and use it in GitHub Desktop.
Python:リダイレクトされるURLに対応したhttpリクエスト(urllib.requestを利用)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
def urllibRequest(): | |
url="https://xxxxxxxxxxxx" | |
response = urllib.request.urlopen(url) | |
content = response.read() | |
if content is not None: | |
response = { | |
'statusCode': 200, | |
'body': content | |
} | |
else: | |
response = { | |
'statusCode': 500, | |
'body': 'Failed to retrieve URL content' | |
} | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment