Created
October 26, 2021 19:44
-
-
Save abenbachir/f157aa9c45931ab7169b434a264e6f27 to your computer and use it in GitHub Desktop.
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 json | |
import os | |
import time | |
def old_function(): | |
print("old_function()") | |
import urllib2 | |
imdsurl = "http://169.254.169.254/metadata/instance?api-version=2019-03-11" | |
print("imdsurl=", imdsurl) | |
req = urllib2.Request(imdsurl, headers={'Metadata':'true'}) | |
res = urllib2.urlopen(req) | |
data = json.loads(res.read()) | |
print("data=", data) | |
def new_function(): | |
import urllib.request, urllib.error, urllib.parse | |
print("new_function()") | |
imdsurl = "http://169.254.169.254/metadata/instance?api-version=2019-03-11" | |
print("imdsurl=", imdsurl) | |
req = urllib.request.Request(imdsurl, headers={'Metadata':'true'}) | |
res = urllib.request.urlopen(req) | |
data = json.loads(res.read().decode('utf-8', 'ignore')) | |
print("data=", data) | |
old_function() | |
new_function() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment