Without a doubt, some plugins you work on or build will make HTTP requests. If you’re looking to use urllib
I strongly suggest you look at requests
! Talk about making HTTP requests easy! readthedocs has everything you need https://requests.readthedocs.io/en/master/
3 Likes
Definitely a good call out! Makes getting started with the python plugin that much easier especially when interacting with REST endpoints and using the built-in JSON decoder that comes with the library.
Can’t get much simpler than the example below for getting started. Just make sure to remember to import requests
:
def run(params={}):
import requests
response = requests.get('https://us.api.insight.rapid7.com/opendata/quota/', headers={"X-Api-Key":"<YOUR API KEY>"})
data = response.json()
return {
"quota_left": data["quota_left"],
"quota_allowed": data["quota_allowed"],
"quota_used": data["quota_used"]
}
1 Like