G
G
Govesinc2021-07-31 16:28:30
Python
Govesinc, 2021-07-31 16:28:30

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'?

Why does TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' occur?

import os
import asyncio
import time

import aiohttp

from aioselenium import Remote, Keys

async def scraper(search):
    capabilities = {
            "browserName": "firefox",
        }

    command_executor = os.getenv('SELENIUM_CLUSTER')

    async with aiohttp.ClientSession() as session:
        print(command_executor)
        remote = await Remote.create(command_executor, capabilities, session)

        async with remote as driver:
            await driver.get("http://www.youtube.com")
            print('Loaded:',await driver.get_title())
            element = await driver.find_element_by_xpath('//input[@id="search"]')
            await element.send_keys(search, Keys.ENTER)
            video_titles = await driver.find_elements_by_xpath('//a[@id="video-title"]')
            for i, video_title in enumerate(video_titles):
                print(search, 'Search Result', i, await video_title.text())

async def main(search_fields):
    await asyncio.gather(*[scraper(search) for search in search_fields])

if __name__ == "__main__":
    s = time.perf_counter()

    search_fields = ["Soccer", "Guatemala", "Guitar", "Computer", "Van Gogh"]
    asyncio.run(main(search_fields))

    elapsed = time.perf_counter() - s
    print(f"Executed in {elapsed:0.2f} seconds.")

Traceback:
Traceback (most recent call last):
  File "/home/user/test_aioselenium.py", line 35, in <module>
    asyncio.run(main(search_fields))
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/user/PycharmProjects/test/test_aioselenium.py", line 29, in main
    await asyncio.gather(*[scraper(search) for search in search_fields])
  File "/home/user/PycharmProjects/test/test_aioselenium.py", line 18, in scraper
    remote = await Remote.create(command_executor, capabilities, session)
  File "/home/user/.local/lib/python3.9/site-packages/aioselenium/aioselenium.py", line 40, in create
    async with self.session.post(self.command_executor+'/session', json=self.desired_capabilities) as resp:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Process finished with exit code 1

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question