Stay in a queue

Hi,
I've written a program which works perfectly well to seek inforamtions on a website. But when too many people are on this site, a queue is set in order to avoid crashes of the server.

The issue is that the script stays in the queue forever. I mean, on a browser we the queue is there you join it automaticly and after a few minutes, you're on the website (even you reload the page, you keep your place in the queue). However, if we launch the site in a private navigation tab, it starts from afresh.

So, I assume that is a question of Session or Cookies (it's not related to the IP).

Does anyone have an idea of how to solve this issue ? I think it should be by using some Session/cookies function but I don't know how to do that.

Thanks,
Djokx.


@Djokx are you using the requests library in your project? This is a repository for a Python library called requests, not a repository to request help for arbitrary problems. If you are using this library, could you share some code so we can help you debug whatever problem it is that you're running into? It's not apparent what this has to do with this library at the moment.


Hi, and thanks for the reply

So here's the function I use:

``` python
session = requests.session()

def CompteMot(mot, site):
    global session
    r = session.post(site)
    P = r.text.upper();
    return P.count(mot)
```

And I have now these errors after a few loops in a while loop in which this function is called :

> Traceback (most recent call last):
>   File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 376, in _make_request
>     httplib_response = conn.getresponse(buffering=True)
> TypeError: getresponse() got an unexpected keyword argument 'buffering'
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 559, in urlopen
>     body=body, headers=headers)
>   File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 378, in _make_request
>     httplib_response = conn.getresponse()
>   File "/usr/lib/python3.4/http/client.py", line 1171, in getresponse
>     response.begin()
>   File "/usr/lib/python3.4/http/client.py", line 351, in begin
>     version, status, reason = self._read_status()
>   File "/usr/lib/python3.4/http/client.py", line 321, in _read_status
>     raise BadStatusLine(line)
> http.client.BadStatusLine: ''
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 370, in send
>     timeout=timeout
>   File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 609, in urlopen
>     _stacktrace=sys.exc_info()[2])
>   File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/util/retry.py", line 245, in increment
>     raise six.reraise(type(error), error, _stacktrace)
>   File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/packages/six.py", line 309, in reraise
>     raise value.with_traceback(tb)
>   File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 559, in urlopen
>     body=body, headers=headers)
>   File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 378, in _make_request
>     httplib_response = conn.getresponse()
>   File "/usr/lib/python3.4/http/client.py", line 1171, in getresponse
>     response.begin()
>   File "/usr/lib/python3.4/http/client.py", line 351, in begin
>     version, status, reason = self._read_status()
>   File "/usr/lib/python3.4/http/client.py", line 321, in _read_status
>     raise BadStatusLine(line)
> requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', BadStatusLine("''",))
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/home/scripts/ScriptReq.py", line 155, in VerifyNbMot
>     Nb_mots = CompteMot(mot, site)
>   File "/home/scripts/ScriptReq.py", line 58, in CompteMot
>     r = session.post(site)
>   File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 511, in post
>     return self.request('POST', url, data=data, json=json, *_kwargs)
>   File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 468, in request
>     resp = self.send(prep, *_send_kwargs)
>   File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 576, in send
>     r = adapter.send(request, **kwargs)
>   File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 420, in send
>     raise ConnectionError(err, request=request)
> requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine("''",))


So it looks like the server is closing the connection without sending a response. Your best bet is to read about [retries](http://www.coglib.com/~icordasc/blog/2014/12/retries-in-requests.html) and set them up. Otherwise this isn't a bug. If you need assistance and are looking for the correct place to ask questions, please head on over to [StackOverflow](https://stackoverflow.com/questions/tagged/python-requests).