Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 581
lc2817 Avatar asked Nov 22 '11 02:11

lc2817


3 Answers

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.

like image 124
lc2817 Avatar answered Sep 19 '22 13:09

lc2817


there are tight controls on who can access the development environment in symfony. Try using the main URL (probably http://localhost:8080/index.php/home)

like image 36
MrGlass Avatar answered Sep 22 '22 13:09

MrGlass


Can you refer some valid address to try your code? I guess that you missed some settings, try to disable robots.

br.set_handle_robots(False)
like image 22
Tiago Maluta Avatar answered Sep 19 '22 13:09

Tiago Maluta