0

I have use requests library from Python to send a get request:

response = requests.get(url, verify, auth, params, headers)

My assumption was that one can send any get-request directly from a browser. For example, in the address line of a browser I need to put something like that:

http://my_url.net?param1=12&param2=777

In the above way I can set url and params that I use in my Python function. But how can I set auth (user name and password) in the get request in case if I use browser to send the request. The same question is applicable to the remaining two arguments: verify and headers.

Roman
  • 124,451
  • 167
  • 349
  • 456
  • 1
    You can try the format of `http://{username}:{password}@my_url.net?param1=12&param2=777` however you cannot just add headers using the browser address bar – PeeHaa Dec 17 '14 at 09:59

2 Answers2

1

Depending on your browser, I guess you can find extensions that can help you do that.

If you use cUrl, you can do something like :

curl http://my_url.net?param1=12&param2=777 --header "Authorization: Basic XXX"

where "xxx" is the Base64 encoding of the string "username:password".

Martin Latrille
  • 749
  • 1
  • 5
  • 12
  • */5 * * * * /usr/bin/wget -qO- http://my_url.net?param1=12&param2=777 --header "Authorization: Basic XXX" >> /home/boo/logs/cron.log – Sadee Oct 08 '18 at 16:59
0

Or try this, using a password manager with a default realm:

url = "http://my_url.net?param1=12&param2=777"

pw_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
pw_mgr.add_password(None, url, username, password)

urllib2.install_opener(
    urllib2.build_opener(urllib2.HTTPBasicAuthHandler(pw_mgr)))

request = urllib2.Request(url)
response = urllib2.urlopen(request)
André Laszlo
  • 15,169
  • 3
  • 63
  • 81