A
A
aqau1232021-11-14 21:15:31
Python
aqau123, 2021-11-14 21:15:31

Why does the server detect this script?

from requests.sessions import cookiejar_from_dict
from torpy.http.requests import TorRequests
from fake_useragent import UserAgent
import os, sys, random
from scripts import config
import time

print('{} Started.'.format(time.strftime('[%H:%M:%S]', time.localtime())))


urls = ['https://ua-pharm.com/wp-content/uploads/2021/11/Silymarin.pdf', 'https://ua-pharm.com/wp-content/uploads/2021/09/apnas-spray-d3-assorted-1-125x125.jpg',
    'https://ua-pharm.com/wp-content/uploads/2020/04/SEPTOGAL_140x189_3D-1.png', 'https://ua-pharm.com/wp-content/uploads/2021/02/vitC-rose.png']

ua = UserAgent()

headers = [{'user-agent': ua.chrome,
    'referer': 'https://ua-pharm.com/',
    'accept': 'image/avif,image/webp,*/*',
    'sec-fetch-dest': 'image',
    'sec-fetch-mode': 'no-cors',
    'sec-fetch-site': 'cross-site'
    } for i in range(0, 100)]

pathDir = os.path.join(config.OUTPUTPATH, 'tor-{}'.format(time.strftime('%a-%b-%Y-%H-%M', time.localtime())))

os.makedirs(pathDir)

def torFetch(session, url):
    with session as session:
        with session.get_session() as s:  
            return s.get(url)

def downloadFile(url, fileName):
    with open(os.path.join(pathDir, fileName), 'wb') as f:
        f.write(torFetch(TorRequests(headers=random.choice(headers)), url).content)


for url in urls:
    name = url.split('/')[::-1][0]
    downloadFile(url, name)
    print('{} Downloaded file. File {}'.format(time.strftime('[%H:%M:%S]', time.localtime()), name))
    print('{} Cooldown {}s.'.format(time.strftime('[%H:%M:%S]', time.localtime()), config.COOLDOWN))
    time.sleep(config.COOLDOWN)


print('{} Finished.'.format(time.strftime('[%H:%M:%S]', time.localtime())))

Actually, here is the code, sometimes the image comes up normal, and sometimes I get
<!doctype html>
<html lang="en">
<head>
  <title>Unauthorized Access</title>
  <meta charset="UTF-8">
  <script src="https://www.google.com/recaptcha/api.js" async defer></script>
  <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
  <link rel="icon" href="data:;base64,iVBORw0KGgo=">
</head>
<body>
    
<div class="container-fluid">
  <img src="data:image/png; .......>
  <div class="alert alert-warning"><h2>The firewall on this server is blocking your connection.</h2></div>
  <p>You need to contact the server owner or hosting provider for further information.</p>
  <p>Your blocked IP address is: <b>205.185.113.225</b></p>
  <p>The hostname of this server is: <b>rocket-cp2.hostsila.org</b></p>

  <br />
  <p>You can try to unblock yourself using ReCAPTCHA:</p>

  <form action="" method="POST">
    <div class="row">
      <div class="col-md-4 col-md-offset-4">
        <div class="panel panel-default">
          <div class="panel-body">
            <div class="g-recaptcha" data-sitekey="6LeS6TEUAAAAADo_Gd9S6DgeV0wYtP0-RG_aSUh1"></div>
          </div>
          <div class="panel-footer text-center">
            <button class='btn btn-primary' type="submit" name="submit">Unblock</button>
          </div>
        </div>
      </div>
    </div>
  </form>

  <br />
  
  <div class="alert alert-info">Please note: Not all unblock requests will be successful as it is dependent on how your IP address is being blocked. If the unblock fails you will need to contact the server owner or hosting provider for further information.</div>
</div>
</body>
</html>

What could be causing this, and how can it be resolved?
There is a solution option through selenium and autocaptcha, but I really would not want to use it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
ScriptKiddo, 2021-11-14
@ScriptKiddo

What could be causing this

For doing robot-like actions
and how can this be solved?

Mimic human. Many proxies, not free, timeouts and a strict limit on the number of requests from one IP.
TOR immediately throws you into the distant world of bots

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question