Multiprocessing doesn't work with Selenium in Python - python

I am being honest, so the reason I use Selenium is because I try to make instagram spam-bot which will send messages to many people where I will ask them to not to be quiet about Russian invasion in Ukraine, because I'm Ukrainian and it's so awful and terrifying what happens around. And this is my duty to help to stop it as mush as I can!
Explanation:
Here is the multishare() function which is called from another function that creates self.followers set, that contains usernames of people who will be sent text. In multishare() function I redefine self.followers as a list and separate it into 4 equal parts to make spammer four times faster. And then I call share() function through the multiprocessing, but it doesn't even open Chrome.
Below you see the code.
Here is the code:
def multishare(self):
self.followers = list(self.followers)
ftq = int(len(self.followers) // 4)
sq = int(len(self.followers) // 2)
tq = int(len(self.followers) // 1.33)
fhq = len(self.followers)
first_part = self.followers[0:ftq]
second_part = self.followers[ftq:sq]
third_part = self.followers[sq:tq]
fourth_part = self.followers[tq:fhq]
self.followers = [first_part, second_part, third_part, fourth_part]
pool = Pool(processes=4)
pool.map(self.share, self.followers)
def share(self, users):
self.safe_get('https://www.instagram.com/')
for user in users:
time.sleep(1)
self.safe_get('https://www.instagram.com/direct/inbox/')
self.element_existence('//*[#id="react-root"]/section/div/div[2]/div/div/div[1]/div[1]/div/div[3]/button').click()
time.sleep(1)
search_user = self.element_existence('/html/body/div[6]/div/div/div[2]/div[1]/div/div[2]/input')
search_user.clear()
time.sleep(1)
search_user.send_keys(user)
time.sleep(1)
self.element_existence("/html/body/div[6]/div/div/div[2]/div[2]/div[1]/div/div[3]/button").click()
time.sleep(1)
self.element_existence("/html/body/div[6]/div/div/div[2]/div[1]/div/div[2]/input").click()
And that's the errors that I got:
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=37193): Max retries exceeded with url: /session/5f6dd5e3e048e0bd62e2dd4b1aa5e8ae/timeouts (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa5089d4250>: Failed to establish a new connection: [Errno 111] Connection refused'))
During handling of the above exception, another exception occurred:
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fa50c23d1f0>: Failed to establish a new connection: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=37193): Max retries exceeded with url: /session/5f6dd5e3e048e0bd62e2dd4b1aa5e8ae/window (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa50c23d1f0>: Failed to establish a new connection: [Errno 111] Connection refused'))
So I cant actually solve this. **It's not about multiprocessing, my main target is to make spammer as fast as it possible. So if u have better idea or just know how to solve my issue, help me please !

Related

Why do I get a connection error using qBittorrentAPI?

I'm trying to run some code from this website but I don't understand why I get this error:
qbittorrentapi.exceptions.APIConnectionError: Failed to connect to qBittorrent. Connection Error: ConnectionError(MaxRetryError("HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /api/v2/auth/login (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001FA519F5840>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))"))
The code in question:
import qbittorrentapi
# instantiate a Client using the appropriate WebUI configuration
qbt_client = qbittorrentapi.Client(
host='localhost',
port=8080,
username='admin',
password='adminadmin',
)
# the Client will automatically acquire/maintain a logged-in state
# in line with any request. therefore, this is not strictly necessary;
# however, you may want to test the provided login credentials.
try:
qbt_client.auth_log_in()
except qbittorrentapi.LoginFailed as e:
print(e)
# display qBittorrent info
print(f'qBittorrent: {qbt_client.app.version}')
print(f'qBittorrent Web API: {qbt_client.app.web_api_version}')
for k,v in qbt_client.app.build_info.items(): print(f'{k}: {v}')
# retrieve and show all torrents
for torrent in qbt_client.torrents_info():
print(f'{torrent.hash[-6:]}: {torrent.name} ({torrent.state})')
# pause all torrents
qbt_client.torrents.pause.all()
I'd really appreciate some help with this, thanks ahead :)

pywhatkit.playonyt is not opening any page

I have MacBook and I am trying to use pywhatkit to play YouTube videos based on the user-provided input. but every time I run my code, it won't take me anywhere and after some time, it will give me this error. (p.s. I am using python 3.8)
Exception has occurred: ConnectionError
HTTPSConnectionPool(host='www.youtube.com', port=443): Max retries exceeded with url: /results?q=Despacito (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fcd17139f70>: Failed to establish a new connection: [Errno 60] Operation timed out'))
this is the code:
import pywhatkit as tube
tube.playonyt('Despacito') # for ex despacito is the user input

Problem using Python client library for Plaid

I'm following the tutorial, but I get an error when I use item_public_token_exchange.
itempublic_tokenexchange
exchange_request = ItemPublicTokenExchangeRequest(
public_token=plaid_token
)
exchange_response = CLIENT.item_public_token_exchange(exchange_request)
the error:
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='sandbox', port=80): Max retries exceeded with url: /item/public_token/exchange (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10f1493a0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))
Not sure what is happening.
It looks like the problem is that you are trying to connect to sandbox instead of sandbox.plaid.com. Make sure you have your host set up as plaid.Environment.Sandbox (or, alternatively, sandbox.plaid.com) and not just sandbox.

IPFS connection : ConnectionError: HTTPConnectionPool(host='localhost', port=5001)

i'm trying to connect my python program to IPFS api to mint some nft.
I started the IPFS daemon on the " /ip4/127.0.0.1/tcp/5001 " but when i try to connect the client i get this error :
ConnectionError: HTTPConnectionPool(host='localhost', port=5001): Max retries exceeded with url: /api/v0/version?stream-channels=true (Caused by NewConnectionError('<ipfshttpclient.requests_wrapper.HTTPConnection object at 0x7fac0ddf97c0>: Failed to establish a new connection: [Errno 111] Connection refused'))
this is my code :
import ipfshttpclient
client = ipfshttpclient.connect()
print(client.version())
it fails on connect() function, i miss something ? what i can do for can start the connection?
Thank you very much for your help.

python repositorytools connection error

I'm trying to put a zip file on artifactory. I'm using 'repositorytools' package and this is how I'm doing it;
try:
local_path = os.path.join(os.getcwd(), "sample-0.1.0.zip")
artifact = repositorytools.LocalArtifact(local_path=local_path,
group='widgets', artifact='sample')
client = repositorytools.repository_client_factory(user='user',
password='pw')
remote_artifacts = client.upload_artifacts(local_artifacts=
[artifact],repo_id='https://artifacts.zeki.com/zeki-development/')
print(remote_artifacts)
except Exception as e:
print colored(("Exception has occurred of type: {} with def:
{}".format(type(e), e)), 'red')
Well all I'm getting this annoying error;
Exception has occurred of type: with def: HTTPSConnectionPool(host='repository', port=443): Max retries exceeded with url: /service/local/artifact/maven/content (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))
So, i tried couple of ways to overcome like increasing retry count but nothing seemed to work. Any ideas?
Thx
repo_id should be only 'zeki-development'.
You need to export environment variable REPOSITORY_URL with value https://artifacts.zeki.com or better pass that value to repository_url parameter of repository_client_factor
``
so it can look like this:
client = repositorytools.repository_client_factory(repository_url='https://artifacts.zeki.com', user='user', password='pw')

Categories