ManivannanMurugavel / selenium-python-aws-lambda

60 stars 25 forks source link

Invalid URL #7

Closed Moon-developer closed 5 years ago

Moon-developer commented 5 years ago

I'm having problems running test events. In my test event I have the following

{
 "url":"www.google.com"
}

when I run test it gives me the following message

{
  "errorMessage": "Message: unknown error: unhandled inspector error: {\"code\":-32000,\"message\":\"Cannot navigate to invalid URL\"}\n  (Session info: headless chrome=62.0.3202.94)\n  (Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.14.88-90.76.amzn2.x86_64 x86_64)\n",
  "errorType": "WebDriverException",
  "stackTrace": [
    [
      "/var/task/lambda_function.py",
      49,
      "lambda_handler",
      "driver.get(event['url'])"
    ],
    [
      "/var/task/selenium/webdriver/remote/webdriver.py",
      332,
      "get",
      "self.execute(Command.GET, {'url': url})"
    ],
    [
      "/var/task/selenium/webdriver/remote/webdriver.py",
      320,
      "execute",
      "self.error_handler.check_response(response)"
    ],
    [
      "/var/task/selenium/webdriver/remote/errorhandler.py",
      242,
      "check_response",
      "raise exception_class(message, screen, stacktrace)"
    ]
  ]
}

along with

START RequestId: ce5f4ee0-0263-484e-95cd-3909c4390241 Version: $LATEST
Starting google.com
Message: unknown error: unhandled inspector error: {"code":-32000,"message":"Cannot navigate to invalid URL"}
  (Session info: headless chrome=62.0.3202.94)
  (Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.14.88-90.76.amzn2.x86_64 x86_64)
: WebDriverException
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 49, in lambda_handler
    driver.get(event['url'])
  File "/var/task/selenium/webdriver/remote/webdriver.py", line 332, in get
    self.execute(Command.GET, {'url': url})
  File "/var/task/selenium/webdriver/remote/webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "/var/task/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: unhandled inspector error: {"code":-32000,"message":"Cannot navigate to invalid URL"}
  (Session info: headless chrome=62.0.3202.94)
  (Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.14.88-90.76.amzn2.x86_64 x86_64)

END RequestId: ce5f4ee0-0263-484e-95cd-3909c4390241
REPORT RequestId: ce5f4ee0-0263-484e-95cd-3909c4390241  Duration: 5548.74 ms    Billed Duration: 5600 ms    Memory Size: 256 MB Max Memory Used: 198 MB 

Any idea what could be happening here? I followed all the steps properly as far as I can. Even tried updating the bin files and changing the permission rights.

ManivannanMurugavel commented 5 years ago

Hi @Moondog360, Please set the full URL like this https://www.google.com

Moon-developer commented 5 years ago

I did do that too. Turned out that it was a timeout issue so changing it from 10 seconds to 15 seconds seemed to fix that problem but now I ran into another problem.

I changed the lambda_function.py to just add one line which is

    if 'url' in event.keys():
        driver.get(event['url'])
        page_data = driver.page_source
        driver.find_element_by_id('action-button').click() # added this line
        print(page_data)
    driver.close()

I zipped the code and uploaded everything like I did before but it's complaining about

{
"errorMessage": "Unable to import module 'lambda_function'"
}

So not sure why this is happening now.

Moon-developer commented 5 years ago

Managed to figure out what was wrong. I was not compressing it correctly. I compressed the folder the code was in instead of going into the folder then select everything and compress to .ZIP. This might have been the same problem one of the guys on your website comments section had and didn't realize everything had to be at root of the zip file if that makes sense.