question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Object of type 'WebDriver' is not JSON serializable

See original GitHub issue

I am not sure how can I combine you reCaptcha solver and selenium session. Fro example simple selenium code:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.hzzo-net.hr/statos_OIB.htm')
driver.find_element_by_id('upoib').send_keys('93335620125')

Now, I would like to execute reCaptcha part, but not sure how to do it. Itried for example:

api_key = xxxxx'
site_key = '6Lc3SAgUAAAAALFnYxUbXlcJ8I9grvAPC6LFTKQs'  # grab from site

client = AnticaptchaClient(api_key)
task = NoCaptchaTaskProxylessTask(driver, site_key)
job = client.createTask(task)
job.join()
print(job.get_solution_response())

But it returns an error in the title. Not sure how to pass selenium session as input?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ad-mcommented, Jan 24, 2018

Extract the site-key from the source code and only pass it and URL. The session does not matter.

It will be something like that (I did not test it exactly). In case of any problems - it remains available. I am glad if you can integrate my library and use it.

import re
from selenium import webdriver

api_key = 'xxxxxxxxxxx'

driver = webdriver.Chrome()
driver.get('http://www.hzzo-net.hr/statos_OIB.htm')
driver.find_element_by_id('upoib').send_keys('93335620125')

url = driver.current_url
site_key = driver.find_element_by_class_name('g-recaptcha').get_attribute('data-sitekey')

client = AnticaptchaClient(api_key)
task = NoCaptchaTaskProxylessTask(url, site_key)
job = client.createTask(task)
job.join()
response = job.get_solution_response()

driver.execute_script('document.getElementsByName("g-recaptcha-response")[0].text = "%s"' % (response))

time.sleep(1)

driver.find_element_by_tag_name('form').submit()

driver.close()

Edit: Fixed pass to script url and driver.

0reactions
ad-mcommented, Jan 24, 2018

@MislavSag , I do not understand what communication with the Anti-captcha service you are talking about?

To proxy communication:

Example mentioned above:

import requests

client = AnticaptchaClient(api_key)
proxies = {
  'http': 'http://10.10.1.10:3128',
  'https': 'http://10.10.1.10:1080',
}

client.session = requests.Session(proxies=proxies)

I would like to point out that proxy communication of you <> anti-captcha makes no sense. Anti-captcha has information about your payment and is an entity in whose interest is not to reveal the identity of customers, so simply share such information will not. The VPN should work for you<>anti-captcha without additional configuration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Object of type WebElement is not JSON serializable
dumps but i have problem with WebElement. I got TypeError: Object of type WebElement is not JSON serializable. This my example code :...
Read more >
Object of type Series is not JSON serializable - Python Help
TypeError : Object of type Series is not JSON serializable. I'm having trouble looping through a list and visiting urls (with selenium) -...
Read more >
TypeError: Object of type function is not JSON serializable
The Python "TypeError: Object of type function is not JSON serializable" occurs when we try to serialize a function to JSON. To solve...
Read more >
Python - TypeError: object of type 'Cell' has no len()
I am working on Selenium with Python. I am writing a code which will fetch the data from an excel file and punch...
Read more >
Python - TypeError Object of type int64 is not JSON serializable
Python - TypeError Object of type int64 is not JSON serializable · Your comment on this question: · No answer to this question....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found