Skip to content

Instantly share code, notes, and snippets.

@ochilab
Last active May 17, 2023 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochilab/261c6dc0178c5f7b5fe6ae4267c6041d to your computer and use it in GitHub Desktop.
Save ochilab/261c6dc0178c5f7b5fe6ae4267c6041d to your computer and use it in GitHub Desktop.
Python:リダイレクトされるURLに対応したhttpリクエスト(urllib.requestを利用)
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