title: PYTHON: requests and response 401
body: <p>I have a little problem with authentication. I am writting a script, which is getting login and password from user(input from keyboard) and then I want to get some data from the website(http not https), but every time I run the script the response is  401.I read some similar posts from stack and I tried this solutions:</p>
  
  <p>Solution 1 </p>
  
  <pre><code>c = HTTPConnection("somewebsite")
  userAndPass = b64encode(b"username:password").decode("ascii")
  headers = { 'Authorization' : 'Basic %s' %  userAndPass }
  c.request('GET', '/', headers=headers)
  res = c.getresponse()
  data = res.read()
  </code></pre>
  
  <p>Solution 2 </p>
  
  <pre><code>with requests.Session() as c:
      url = 'somewebsite'
      USERNAME = 'username'
      PASSWORD = 'password'
      c.get(url)
      login_data = dict(username = USERNAME, password = PASSWORD)
      c.post(url,data = login_data)
      page = c.get('somewebsite', headers = {"Referer": "somwebsite"})
      print(page)
  </code></pre>
  
  <p>Solution 3</p>
  
  <pre><code>www = 'somewebsite'
  value ={'filter':'somefilter'}
  data = urllib.parse.urlencode(value)
  data=data.encode('utf-8')
  req = urllib.request.Request(www,data)
  resp = urllib.request.urlopen(req)
  respData = resp.read()
  print(respData)
  x = urllib.request.urlopen(www,"username","password")
  print(x.read())'
  </code></pre>
  
  <p>I don't know how to solve this problem. Can somebody give me some link or tip ? </p>