title: AttributeError: 'bytes' object has no attribute 'data'
body: <p>the purpose of this script is to use python to login on a website with login and pass</p>
  
  <p>launching the script with login and pass as parameters.</p>
  
  <pre><code>[vegasus@Ph3NyX:~]$python3 grabbit.py mylogin mypass
  
  Traceback (most recent call last):
    File "/Users/vegasus/PycharmProjects/Lesson_Python/grabbit.py", line 102, in &lt;module&gt;
      WebLogin('mylogin', 'mypass')
    File "/Users/vegasus/PycharmProjects/Lesson_Python/grabbit.py", line 61, in __init__
      response = self.login()
    File "/Users/vegasus/PycharmProjects/Lesson_Python/grabbit.py", line 82, in login
      response = self.opener.open(login_url.encode(), login_data.encode())
    File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py", line 444, in open
      req.data = data
  AttributeError: 'bytes' object has no attribute 'data'
  </code></pre>
  
  <p>here is the script :</p>
  
  <pre><code>import urllib, urllib.request, urllib.parse
  import http.cookiejar
  import sys
  
  class WebLogin(object):
  
      def __init__(self, username, password):
  
          # url for website we want to log in to
          self.base_url = 'https://www.mywebsite.com'
          # login action we want to post data to
          # could be /login or /account/login or something similar
          self.login_action = '/en/login'
          # file for storing cookies
          self.cookie_file = 'login.cookies'
  
          # user provided username and password
          self.username = username
          self.password = password
  
          # set up a cookie jar to store cookies
          self.cj = http.cookiejar.MozillaCookieJar(self.cookie_file)
  
          # set up opener to handle cookies, redirects etc
          self.opener = urllib.request.build_opener(
              urllib.request.HTTPRedirectHandler(),
              urllib.request.HTTPHandler(debuglevel=0),
              urllib.request.HTTPSHandler(debuglevel=0),
              urllib.request.HTTPCookieProcessor(self.cj)
          )
  
          # pretend we're a web browser and not a python script
          self.opener.addheaders = [('User-agent',
              ('Mozilla/4.0 (compatible; MSIE 6.0; '
              'Windows NT 5.2; .NET CLR 1.1.4322)'))
          ]
  
          # open the front page of the website to set and save initial cookies
          response = self.opener.open(self.base_url)
          self.cj.save()
  
          # try and log in to the site
          response = self.login()
  
          print (response.read())
  
      # method to do login
      def login(self):
  
          # parameters for login action
          # may be different for different websites
          # check html source of website for specifics
          login_data = urllib.parse.urlencode({
              'username' : self.username,
              'password' : self.password,
              'remember_me' : True
          })
  
          # construct the url
          login_url = self.base_url + self.login_action
          # then open it
          response = self.opener.open(login_url.encode(), login_data.encode())
          # save the cookies and return the response
          self.cj.save()
          return response
  
  
  if __name__ == "__main__":
  
      args = sys.argv
  
      # check for username and password
      if len(args) != 3:
          print ("Incorrect number of arguments")
          print ("Argument pattern: username password")
          exit(1)
  
      username = args[1]
      password = args[2]
  
      # initialise and login to the website
      WebLogin('mylogin', 'mypass')
  </code></pre>