title: Setting custom headers on a python-wordpress-xmlrpc request
body: <p>I'm trying to connect to a Wordpress blog using XMLRPC. I'm using the latest library, v2.3 (<a href="http://python-wordpress-xmlrpc.readthedocs.org/en/latest/" rel="nofollow">http://python-wordpress-xmlrpc.readthedocs.org/en/latest/</a>).</p>
  
  <p>I get the following exception when I try to initialize the client: </p>
  
  <pre><code>ServerConnectionError: &lt;ProtocolError for www.myblogaddress.com/xmlrpc.php: 403 Forbidden&gt;
  </code></pre>
  
  <p>I noticed that this happens before the username &amp; password are checked, so it doesn't have anything to do with invalid credentials. I believe it might require some custom headers, like user agent, but I don't know how to set a custom transport param.</p>
  
  <p>I have copied the code from the python-wordpress-xmlrpc library and modified it so I could make tests. Here is what I have so far:</p>
  
  <pre><code>from xmlrpclib import Transport
  
  class SpecialTransport(Transport):
  
      def send_content(self, connection, request_body):
  
          connection.putheader("Content-Type", "text/xml")
          connection.putheader("Content-Length", str(len(request_body)))
          connection.putheader('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11')
  
          connection.putheader('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
          connection.putheader('Accept-Charset','ISO-8859-1,utf-8;q=0.7,*;q=0.3')
          connection.putheader('Accept-Encoding','none')
          connection.putheader('Accept-Language', 'en-US,en;q=0.8')
          connection.putheader('Connection', 'keep-alive')
  
          connection.endheaders()
          if request_body:
              connection.send(request_body)
  
  url = "{test_url_here}"
  
  try:
      server = xmlrpc_client.ServerProxy(url, allow_none=True, transport=SpecialTransport())
      supported_methods = server.mt.supportedMethods()
  
  except xmlrpc_client.ProtocolError as err:
  
      print "A protocol error occurred"
      print "URL: %s" % err.url
      print "HTTP/HTTPS headers: %s" % err.headers
      print "Error code: %d" % err.errcode
      print "Error message: %s" % err.errmsg
  </code></pre>
  
  <p>I should mention I have successfully connected to the same blog from a PHP script, so I believe it has something to do with the Python request. Any idea why this doesn't work?</p>
  
  <p>Thanks for the help!</p>