title: Bearer Token authorization header in SOAP client with Zeep and Python
body: <p>I am new to SOAP requests and programming in general. I would like to access a WSDL that requires a Bearer Token Authorization to use one of their services.</p>
  
  <p>Info about the service I want to access after calling  <code>pyhton -mzeep *WSDL_url*</code>:</p>
  
  <pre><code>  getInfo(param1: xsd:string, param2: xsd:anySimpleType, param3: xsd:anySimpleType) -&gt; out: ns0:ResponseCurve[]
  </code></pre>
  
  <p>First I recieve the token with:</p>
  
  <pre><code>import zeep
  user = 'my_user'
  userpass = 'my_pass'
  token = client.service.getAuthToken(user,userpass)
  </code></pre>
  
  <p>Then I would like to request the service getInfo that requires three parameters:</p>
  
  <pre><code>my_info = client.service.getInfo('param1', 'param2', 'param3')
  </code></pre>
  
  <p>I know by the provider that the Token is needed each time I want to access this service and in documentation the following is stated about headers regarding Authentification:</p>
  
  <p><em>Authorization: Bearer eyJhbGciOiJIUzI1N[...]</em></p>
  
  <p>I have tried to pass the header as dict in <code>_soapheaders</code> but not working.</p>
  
  <p>I can access the service by using a forced requests:</p>
  
  <pre><code>def get_response_from_provider(token, param1, param2, param3):
      url = "WSDL url"
      headers = {'Authorization': 'Bearer ' + token,
                 'content-type': 'text/xml'}
      body = """
      &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsl="uri"&gt;
          &lt;soapenv:Header/&gt;
          &lt;soapenv:Body&gt;
              &lt;wsl:getInfo&gt;
                  &lt;param1&gt;""" + param1 + """&lt;/param1&gt;
                  &lt;param2&gt;""" + param2 + """ &lt;/param2&gt;
                  &lt;param3&gt;""" + param3 + """ &lt;/param3&gt;
              &lt;/wsl:getInfo&gt;
          &lt;/soapenv:Body&gt;
      &lt;/soapenv:Envelope&gt;"""
      response = requests.post(url, data=body, headers=headers)
      print("Info recieved...")
  
      return response
  </code></pre>
  
  <p>However I would like to access the Services through the SOAP client.</p>
  
  <p>This is how they add the token in PHP:</p>
  
  <pre><code>$soap-&gt;soapClient-&gt;_stream_context = stream_context_create([
      'http' =&gt; [
          'header' =&gt; sprintf('Authorization: Bearer %s', $authTokenResponse-&gt;token)
      ]
  ]);
  </code></pre>
  
  <p>Any Idea on how to add the header with the Token to the client request in Python??</p>
  
  <p>I have seen many post with SOAP+Python in SOF but could not solve the problem. Even with Zeep documentation I have not been able to make it work.</p>
  
  <p>Thanks</p>