0

I'm trying to use selenium with multiprocessing manager to grabbing courses, one subprocess to find if anyone quit the course and the other one refreshing the adding courses' page to prevent connection timed out. But it shows me the wrong message "multiprocessing.managers.RemoteError", can anyone help?

import urllib.request as req
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.wait import WebDriverWait
import time
import multiprocessing as mp
from multiprocessing.managers import BaseManager, BaseProxy

class CustomManager(BaseManager):
    pass

def find(url, requestData, chooseStudent, driver):
    while True:
        request=req.Request(url, headers={
            "content-type":"application/json; charset=utf-8"
        }, data=json.dumps(requestData).encode("utf-8"))

        with req.urlopen(request) as response:
            result=response.read().decode("utf-8")

        result=json.loads(result)

        if int(result[0]["ChooseStudent"])<chooseStudent:
            ADDgo = driver.find_element(By.ID, "SingleAdd")
            ADDgo.click()
            break

def refresh(driver):
    while True:
        time.sleep(200)
        driver.refresh()

if __name__=='__main__':
    url="https://querycourse.ntust.edu.tw/querycourse/api/courses"
    requestData={"Semester":"1112","CourseNo":"GE3710302","CourseName":"","CourseTeacher":"","Dimension":"","CourseNotes":"","ForeignLanguage":0,"OnlyGeneral":0,"OnleyNTUST":0,"OnlyMaster":0,"OnlyUnderGraduate":0,"OnlyNode":0,"Language":"zh"}
    chooseStudent=51
    account='xxxxxxx'
    password='xxxxxxx'
    classid='GE3710302'

    CustomManager.register('set', webdriver.Chrome)
    with CustomManager() as manager:
        driver = manager.set()
        # driver = webdriver.Chrome()
        driver.get("https://stuinfosys.ntust.edu.tw/NTUSTSSOServ/SSO/Login/CourseSelection")
        UserName = WebDriverWait(driver, timeout=10).until(lambda d: d.find_element(By.NAME,"UserName"))
        UserName.send_keys(account)
        Password = driver.find_element(By.NAME, "Password")
        Password.send_keys(password)
        btnLogIn = driver.find_element(By.NAME, "btnLogIn")
        btnLogIn.click()
        
        p1 = mp.Process(target=find, args=(url, requestData, chooseStudent, driver,))
        p2 = mp.Process(target=refresh, args=(driver,))

        p1.start()
        p2.start()

the error message like this:

DevTools listening on ws://127.0.0.1:55650/devtools/browser/5d3feeb5-0da8-4f51-b812-eabd43d34c47
Traceback (most recent call last):
  File "D:\python_training\web crawler\kk_manager.py", line 48, in <module>
    driver = manager.set()
  File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\multiprocessing\managers.py", line 723, in temp
    token, exp = self._create(typeid, *args, **kwds)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\multiprocessing\managers.py", line 608, in _create
    id, exposed = dispatch(conn, None, 'create', (typeid,)+args, kwds)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\multiprocessing\managers.py", line 93, in dispatch
    raise convert_to_error(kind, result)
multiprocessing.managers.RemoteError: 
---------------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\multiprocessing\managers.py", line 209, in _handle_request
    result = func(c, *args, **kwds)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\multiprocessing\managers.py", line 390, in create
    exposed = public_methods(obj)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\multiprocessing\managers.py", line 133, in public_methods
    return [name for name in all_methods(obj) if name[0] != '_']
  File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\multiprocessing\managers.py", line 124, in all_methods
    func = getattr(obj, name)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1112, in orientation
    return self.execute(Command.GET_SCREEN_ORIENTATION)['value']
  File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 428, in execute
    self.error_handler.check_response(response)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown command: unknown command: session/1a22e1a76b3e9ab242db77c857093acd/orientation
Stacktrace:
Backtrace:
        (No symbol) [0x011337D3]
        (No symbol) [0x010C8B81]
        (No symbol) [0x00FCB36D]
        (No symbol) [0x01017CF0]
        (No symbol) [0x01017544]
        (No symbol) [0x00FA5427]
        (No symbol) [0x00FA5B0E]
        (No symbol) [0x00FA5EEA]
        GetHandleVerifier [0x013AABF2+2510930]
        GetHandleVerifier [0x013D8EC1+2700065]
        GetHandleVerifier [0x013DC86C+2714828]
        GetHandleVerifier [0x011E3480+645344]
        (No symbol) [0x010D0FD2]
        (No symbol) [0x00FA516A]
        (No symbol) [0x00FA4B96]
        GetHandleVerifier [0x013F8C9C+2830588]
        BaseThreadInitThunk [0x75E97D69+25]
        RtlInitializeExceptionChain [0x770CBB9B+107]
        RtlClearBits [0x770CBB1F+191]
Nicholas
  • 1
  • 1
  • according to your error message your client tries to invoke webdriver command that is not supported by your actual driver. Probably you are using some code that was supposed to run on mobile devices but you're running it on desktop? – Alexey R. Feb 13 '23 at 13:32

0 Answers0