TypeError: unsupported operand type(s) for -=: 'unicode' and 'int'

While sending huge amount requests to Unit rejecting requests, However I am using max_retries=20 still i am getting this error message

```
File "/home/mkosuri/venv/local/lib/python2.7/site-packages/RequestsLibrary/RequestsKeywords.py", line 258, in post_request response = self._post_request(session, uri, data, headers, files, redir, timeout) 
File "/home/mkosuri/venv/local/lib/python2.7/site-packages/RequestsLibrary/RequestsKeywords.py", line 556, in _post_request allow_redirects=allow_redirects) 
File "/home/mkosuri/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 511, in post return self.request('POST', url, data=data, json=json, **kwargs) 
File "/home/mkosuri/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 468, in request resp = self.send(prep, **send_kwargs) 
File "/home/mkosuri/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 576, in send r = adapter.send(request, **kwargs) 
File "/home/mkosuri/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 370, in send timeout=timeout File "/home/mkosuri/yang_gen/venv/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 609, in urlopen _stacktrace=sys.exc_info()[2]) 
File "/home/mkosuri/venv/local/lib/python2.7/site-packages/requests/packages/urllib3/util/retry.py", line 226, in increment total -= 1
```

Any workaround for this issue?


Do you receive it always? Under what conditions do you receive it? What does your code look like? What version of requests are you using? From where did you install it?


Do you receive it always? 

>  Yes

Under what conditions do you receive it? 

> I am sending around different 5K combination of GET, PUT, PATCH, POST 

What does your code look like?

``` Python
resp = session.get(self._get_url(session, uri),
                                   headers=headers,
                                   params=params,
                                   cookies=self.cookies, timeout=self.timeout,
                                   allow_redirects=allow_redirects)   
```

similarly for all other sessions

What version of requests are you using?

> 2.8

From where did you install it?

> I am using Jenkins virtual environments, through pip install --upgrade -r requirements
> requests >= 2.8


So you're not under any circumstances setting the `retries` parameter, or any other similar parameter? Do you have values set on the session? Do you have a custom transport adapter?


I am using HTTPAdapter for max_retries, while creating session

``` Python
s = session = requests.Session()
if max_retries > 0:
            a = requests.adapters.HTTPAdapter(max_retries=max_retries)
            s.mount('https://', a)
            s.mount('http://', a)
```


Ok, can you please print the values of `max_retries` for each adapter before each request? Both the value and the type. Something like this:

``` python
for k, v in s.adapters.items():
    print "Adapter %s: max_retries is %s (%s)" % (k, v, type(v))
```


Send a GET request on the session object found using the

```
Start / End / Elapsed:  20151229 17:24:56.627 / 20151229 17:24:56.636 / 00:00:00.009
17:24:56.629    INFO    Starting new HTTP connection (7): 10.11.13.96   
17:24:56.635    INFO    Adapter https://: max_retries is <requests.adapters.HTTPAdapter object at 0x7f6ca703a250> (<class 'requests.adapters.HTTPAdapter'>)
Adapter http://: max_retries is <requests.adapters.HTTPAdapter object at 0x7f6ca703a250> (<class 'requests.adapters.HTTPAdapter'>)  
17:24:56.636    FAIL    TypeError: unsupported operand type(s) for -=: 'unicode' and 'int'
```

Send a POST request on the session object found using the

```
Start / End / Elapsed:  20151229 17:24:56.644 / 20151229 17:24:56.653 / 00:00:00.009
17:24:56.645    INFO    Starting new HTTP connection (8): 10.11.13.96   
17:24:56.652    INFO    Adapter https://: max_retries is <requests.adapters.HTTPAdapter object at 0x7f6ca703a250> (<class 'requests.adapters.HTTPAdapter'>)
Adapter http://: max_retries is <requests.adapters.HTTPAdapter object at 0x7f6ca703a250> (<class 'requests.adapters.HTTPAdapter'>)  
17:24:56.652    FAIL    TypeError: unsupported operand type(s) for -=: 'unicode' and 'int'
```

Send a PATCH request on the session object found using the

```
Start / End / Elapsed:  20151229 17:24:56.683 / 20151229 17:24:56.688 / 00:00:00.005
17:24:56.684    INFO    Starting new HTTP connection (10): 10.11.13.96  
17:24:56.688    INFO    Adapter https://: max_retries is <requests.adapters.HTTPAdapter object at 0x7f6ca703a250> (<class 'requests.adapters.HTTPAdapter'>)
Adapter http://: max_retries is <requests.adapters.HTTPAdapter object at 0x7f6ca703a250> (<class 'requests.adapters.HTTPAdapter'>)  
17:24:56.688    FAIL    TypeError: unsupported operand type(s) for -=: 'unicode' and 'int'
```


Oh, I apologise, my sample code was wrong (this is what I get for responding to bug reports before caffeine). Try this one:

``` python
for k, v in s.adapters.items():
    print "Adapter %s: max_retries is %s (%s)" % (k, v.max_retries, type(v.max_retries))
```


Send a GET request on the session object found using the

```
Start / End / Elapsed:  20151229 17:36:24.093 / 20151229 17:36:24.099 / 00:00:00.006
17:36:24.094    INFO    Starting new HTTP connection (9): 10.11.11.179  
17:36:24.098    INFO    Adapter https://: max_retries is Retry(total=20, connect=None, read=None, redirect=None) (<class 'requests.packages.urllib3.util.retry.Retry'>)
Adapter http://: max_retries is Retry(total=20, connect=None, read=None, redirect=None) (<class 'requests.packages.urllib3.util.retry.Retry'>)  
17:36:24.098    FAIL    TypeError: unsupported operand type(s) for -=: 'unicode' and 'int'
```

Send a POST request on the session object found using the

```
17:36:24.109    INFO    Starting new HTTP connection (10): 10.11.11.179     
17:36:24.113    INFO    Adapter https://: max_retries is Retry(total=20, connect=None, read=None, redirect=None) (<class 'requests.packages.urllib3.util.retry.Retry'>)
Adapter http://: max_retries is Retry(total=20, connect=None, read=None, redirect=None) (<class 'requests.packages.urllib3.util.retry.Retry'>)  
17:36:24.114    FAIL    TypeError: unsupported operand type(s) for -=: 'unicode' and 'int'
```

Send a PATCH request on the session object found using the

```
17:36:24.421    INFO    Starting new HTTP connection (30): 10.11.11.179     
17:36:24.430    INFO    Adapter https://: max_retries is Retry(total=20, connect=None, read=None, redirect=None) (<class 'requests.packages.urllib3.util.retry.Retry'>)
Adapter http://: max_retries is Retry(total=20, connect=None, read=None, redirect=None) (<class 'requests.packages.urllib3.util.retry.Retry'>)  
17:36:24.431    FAIL    TypeError: unsupported operand type(s) for -=: 'unicode' and 'int'
```


Hmm, well this error looks impossible. Can you turn on debug level logging for the `requests` package please, and then show me the logs from requests just before the error?


Hey @vkosuri what is the library providing "RequestsLibrary/RequestsKeywords.py" in your traceback? It seems like you're using something else that calls requests. If you have a link to that source, I'd like to inspect that as well.


Sorry, The root cause of the issue is, Robot framework scalar variable are Unicode values, we have to explicitly type cast variable while passing to other library procedures. https://github.com/robotframework/robotframework/issues/2273 

I resolved this issue by type casting max_retries to integer

``` Python
s = session = requests.Session()
if max_retries > 0:
            a = requests.adapters.HTTPAdapter(max_retries=int(max_retries))
            s.mount('https://', a)
            s.mount('http://', a
```

Thank all your support.