title: lxml.html set error "TypeError: Argument must be bytes or unicode, got 'NoneType' "
body: <p>I am trying to put a 'defer' attribute into script tags using lxml.html but I get the error </p>
  
  <p>TypeError: Argument must be bytes or unicode, got 'NoneType'</p>
  
  <p>or</p>
  
  <p>TypeError: set() takes exactly 2 positional arguments (1 given)</p>
  
  <p>if I use</p>
  
  <pre><code>script.set('defer')
  </code></pre>
  
  <p>According to <a href="http://lxml.de/lxmlhtml.html" rel="nofollow noreferrer">http://lxml.de/lxmlhtml.html</a> </p>
  
  <p>.set(key, value=None):
  Sets an HTML attribute. If no value is given, or if the value is None, it creates a boolean attribute like </p>
  
  <pre><code>&lt;form novalidate&gt;&lt;/form&gt; 
  </code></pre>
  
  <p>or </p>
  
  <pre><code>&lt;div custom-attribute&gt;&lt;/div&gt;.
  </code></pre>
  
  <p>my code is </p>
  
  <pre><code>import lxml.html  
  
  htmldoc = lxml.html.parse( file )   
  headElement = htmldoc.find("head")
  listOfScripts = headElement.xpath("script")
  
  if len(listOfScripts) &gt; 0:
      for script in listOfScripts:
          script.set('defer', value=None)
  </code></pre>