0

I'm trying to run selenium webdriver chrome script but getting error

"Expecting value: line 1 column 1 (char 0)".

The error occurs when I call webdriver. As I understand it, driver() is really empty before I pass a url to it using the get() method. How can I make json ignore that driver is empty? This happens on the Yandex.Cloud.Functions platform.

from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from fake_headers import Headers
import time
import telebot
import datetime
import requests
import pytz

def lambda_handler(event, context):
    # Process event from aws and respond
    process_event(event)
    return {
        'statusCode': 200
    }

options = Options()
options.add_argument('--no-sandbox')
options.add_argument("--headless")
options.add_argument('--disable-dev-shm-usage')

header = Headers(
    browser="chrome",  # Generate only Chrome UA
    os="win",  # Generate only Windows platform
    headers=False # generate misc headers
)
customUserAgent = header.generate()['User-Agent']

options.add_argument(f"user-agent={customUserAgent}")


driver = webdriver.Chrome(options = options)


{
    "errorMessage": "Expecting value: line 1 column 1 (char 0)",
    "errorType": "JSONDecodeError",
    "stackTrace": [
        "  File \"/function/runtime/runtime.py\", line 172, in load_handler\n    mod = importlib.import_module(file_name)\n",
        "  File \"/function/runtime/lib/python3.9/importlib/__init__.py\", line 127, in import_module\n    return _bootstrap._gcd_import(name[level:], package, level)\n",
        "  File \"<frozen importlib._bootstrap>\", line 1030, in _gcd_import\n",
        "  File \"<frozen importlib._bootstrap>\", line 1007, in _find_and_load\n",
        "  File \"<frozen importlib._bootstrap>\", line 986, in _find_and_load_unlocked\n",
        "  File \"<frozen importlib._bootstrap>\", line 680, in _load_unlocked\n",
        "  File \"<frozen importlib._bootstrap_external>\", line 850, in exec_module\n",
        "  File \"<frozen importlib._bootstrap>\", line 228, in _call_with_frames_removed\n",
        "  File \"/function/code/index.py\", line 35, in <module>\n    driver = webdriver.Chrome(options = options)\n",
        "  File \"/function/code/selenium/webdriver/chrome/webdriver.py\", line 80, in __init__\n    super().__init__(\n",
        "  File \"/function/code/selenium/webdriver/chromium/webdriver.py\", line 101, in __init__\n    self.service.start()\n",
        "  File \"/function/code/selenium/webdriver/common/service.py\", line 97, in start\n    path = SeleniumManager().driver_location(browser)\n",
        "  File \"/function/code/selenium/webdriver/common/selenium_manager.py\", line 81, in driver_location\n    result = self.run((binary, browser_flag, browser, output_flag, output))\n",
        "  File \"/function/code/selenium/webdriver/common/selenium_manager.py\", line 99, in run\n    output = json.loads(stdout)\n",
        "  File \"/function/runtime/lib/python3.9/json/__init__.py\", line 346, in loads\n    return _default_decoder.decode(s)\n",
        "  File \"/function/runtime/lib/python3.9/json/decoder.py\", line 337, in decode\n    obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n",
        "  File \"/function/runtime/lib/python3.9/json/decoder.py\", line 355, in raw_decode\n    raise JSONDecodeError(\"Expecting value\", s, err.value) from None\n"
    ]
}

Kulasangar
  • 9,046
  • 5
  • 51
  • 82
  • The error means you received an empty string. Figure out why. Probably examine the result code from the API; a well-designed API would tell you when there is an error. – tripleee Apr 20 '23 at 11:36
  • also try to handle cases when there's an empty string @Semyon – Kulasangar Apr 20 '23 at 11:37

0 Answers0