Search code examples
pythonsymfony1mechanize

Symfony and mechanize


I am trying to access to a local website designed with the Symfony framework. It works perfectly with the web browser and with CURL but when I use Mechanize I always got the 401 unauthorized answer for the server.

import mechanize


# Browser
br = mechanize.Browser()
br.set_debug_http(True)
br.set_debug_redirects(True)
br.set_debug_responses(True)

# Does not change anything even if we change thos
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

# Here is my website
r = br.open('http://localhost:8080/frontend_dev.php/home')
html = r.read()

# Show the html source 
print html

Do you have any idea why it behaves like this?

Thanks


Solution

  • I finally found the answer by myself. There is a bug in the sfDoctrineGuardPlugin (and sfGuardPlugin) that causes this behavior as stated here. I applied the patch and the problem is solved.