7

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

lc2817
  • 3,722
  • 16
  • 40

5 Answers5

6

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.

lc2817
  • 3,722
  • 16
  • 40
  • It's an old bug, I think you must have an old version of the plugin. Consider updating. – greg0ire Nov 28 '11 at 08:49
  • The bug has been corrected in august this year. And the last release of sfDoctrineGuard has been done is 2010. I don't think that you are right. What do you suggest: http://www.symfony-project.org/plugins/sfDoctrineGuardPlugin – lc2817 Nov 28 '11 at 19:58
  • I suggest to use Symfony2 Seriously, I don't know why the last release is so old... perhaps jwage is too busy with doctrine2 / sf2 ... – greg0ire Nov 28 '11 at 20:06
1

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)

MrGlass
  • 9,094
  • 17
  • 64
  • 89
  • It didn't solved the issue. I just tried it and got the same error – lc2817 Nov 22 '11 at 16:15
  • Sorry. I assume you cleared your cache? Do you have any credentials or anything required? – MrGlass Nov 22 '11 at 16:26
  • For the cache: yes. I don't have any credential needed for the home page, for some pages afterwards yes. And it works perfectly with curl, I don't know why... – lc2817 Nov 22 '11 at 16:29
  • Thank you for helping anyway. It doesn't change anything whetherthe app is in production or not. – lc2817 Nov 22 '11 at 16:35
1

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)
Tiago Maluta
  • 153
  • 1
  • 1
  • 9
  • I tried this and it didn't change anything. No I can't provide a valid address to try my code right no (sorry maybe later). – lc2817 Nov 26 '11 at 06:21
1

I don't know anything about Symfony framework, but as you are getting 'Error : 401 ' . Adding these lines might work .

br.add_password('http://localhost:8080/frontend_dev.php/home', 'username', 'password')
br.open('http://localhost:8080/frontend_dev.php/home')
Code Lღver
  • 15,573
  • 16
  • 56
  • 75
anshul410
  • 824
  • 2
  • 11
  • 23
1

please see http://trac.symfony-project.org/ticket/4474

Tao Song
  • 133
  • 7