Skip to content

Instantly share code, notes, and snippets.

@abenbachir
Created October 26, 2021 19:44
Show Gist options
  • Save abenbachir/f157aa9c45931ab7169b434a264e6f27 to your computer and use it in GitHub Desktop.
Save abenbachir/f157aa9c45931ab7169b434a264e6f27 to your computer and use it in GitHub Desktop.
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