Forums

Flask | Zyte (former Crawlera) session.post proxy handling

Hello,

I have a Zyte accoubnt and already did the API things.

proxy={
    "http": "http://<API_KEY>:@proxy.crawlera.com:8011/",
    "https": "http://<API_KEY>:@proxy.crawlera.com:8011/"
}

There is longer version but that is quite enough for now.

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:46.0) Gecko/20100101 Firefox/46.0'}
s = requests.Session()
s.proxies.update(proxy)
#s.verify = "/home/TromotiXC/tromotixcapp/static/zyte-proxy-ca.crt" ??
s.headers.update(headers)
s.post(login_url, data = data, verify="/home/TromotiXC/tromotixcapp/static/zyte-proxy-ca.crt")

With requests.get it works. But I have to get datas which needed to be logged in so I have to make a session round and the further requests with s.get. But I don't see the datas what I should see with logged in.

Other the third s.get I try to print .text but that is empty.

Thank you in advance!

My guess would be that the site you're trying to login to is rejecting the login for some reason. Check the content you're getting back from the POST request to see if it indicates why.

Thank you, Glenn!

I get back this: {"redirect":"***office.php","status":"success"} from session.post.

So it seems the login is okay.

I do the rest with this: session.get(url, timeout=timeout, proxies=proxy, verify="***.crt")

The page already downloaded, I checked. So it is okay. The main problem is the get.text. I shows that is nothing in it.

If I run the code from desktop, it works. And additional info: before the proxy the code already worked.

Thank you in advance!

As you're setting proxies for the session object, maybe remove proxies=proxy from session.get and check if it changes the behaviour. Also check what is the status code for the response of that call.

I already tried that one also. I tried with several session.get requests but none of them works.

Not some get comes down, but get that one:

2021-07-04 21:24:34,926: Exception on / [POST]

Traceback (most recent call last):

File "/usr/lib/python3.8/site-packages/flask/app.py", line 2446, in wsgi_app

response = self.full_dispatch_request()

File "/usr/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request

return self.finalize_request(rv)

File "/usr/lib/python3.8/site-packages/flask/app.py", line 1967, in finalize_request

response = self.make_response(rv)

File "/usr/lib/python3.8/site-packages/flask/app.py", line 2096, in make_response

raise TypeError(

TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.

I know which session.get not works but the previous seems okay and that one not. The code not from pythonanywhere works also...

And the previous session.get text is not exactly what is on the website...

When you get an error that says "The view function did not return a valid response" it means that the view function that your request executed needed to return some sort of response and didn't. Make sure that every code path through your view returns something that can be a response.

From you earlier message - if the code worked without the proxy before, then my guess would be that the proxy is the issue. Contact the providers of the proxy to ask them what is happening.