# Make requests to download file in url with nameko

**URL:** <https://discourse.nameko.io/t/make-requests-to-download-file-in-url-with-nameko/492>\
**Category:** Uncategorized\
**Created:** [September 3, 2019, 9:53am UTC](https://discourse.nameko.io/t/make-requests-to-download-file-in-url-with-nameko/492 "2019-09-03T09:53:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuut007](https://avatars.discourse-cdn.com/v4/letter/y/e9c0ed/32.png) [@yuut007](https://discourse.nameko.io/u/yuut007)\
**Post date:** [September 3, 2019, 9:53am UTC](https://discourse.nameko.io/t/make-requests-to-download-file-in-url-with-nameko/492/1 "2019-09-03T09:53:18Z")

</div>

Hey my friend, I need your help. I try to download a file in url like ([http://google.com/favicon.ico](http://google.com/favicon.ico)). It works well locally with (“requests” , “urllib3” , “urllib.request” ), but it doesn’t work with nameko. I can’t solve this problem. My code likes this:

```
from nameko.web.handlers import http
import requests

class MyService:
    name = "my_service"

    @http("POST", "/post/my")
    def do_post(self, request):
        url = "http://google.com/favicon.ico"
        r = requests.get(url, allow_redirects=True)
        print(r.status)
        open("google.ico", "wb").write(r.content)
        return u"received: {}".format(request.get_data(as_text=True))

```

and the error is always like this.  
“wrap\_socket() got an unexpected keyword argument ‘\_context’”

Can anyone help me pls.

---

<div class="post-metadata">

**Author:** ![yuut007](https://avatars.discourse-cdn.com/v4/letter/y/e9c0ed/32.png) [@yuut007](https://discourse.nameko.io/u/yuut007)\
**Post date:** [September 3, 2019, 9:56am UTC](https://discourse.nameko.io/t/make-requests-to-download-file-in-url-with-nameko/492/2 "2019-09-03T09:56:18Z")

</div>

> [@yuut007](#):
>
> “requests” , “urllib3” , “urllib.request”

In fact, I have already tried “requests” , “urllib3” , “urllib.request” . these three libs of python 3.7.4. But They all have the same error.

And it works well in python3.7.4 without nameko.

---

<div class="post-metadata">

**Author:** ![Jakub\_Borys](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/jakub_borys/32/7_2.png) [@Jakub\_Borys](https://discourse.nameko.io/u/Jakub_Borys)\
**Post date:** [September 3, 2019, 12:38pm UTC](https://discourse.nameko.io/t/make-requests-to-download-file-in-url-with-nameko/492/3 "2019-09-03T12:38:22Z")

</div>

Could you paste entire stack trace of the error here? How are you running the service?

---

<div class="post-metadata">

**Author:** ![yuut007](https://avatars.discourse-cdn.com/v4/letter/y/e9c0ed/32.png) [@yuut007](https://discourse.nameko.io/u/yuut007)\
**Post date:** [September 3, 2019, 12:53pm UTC](https://discourse.nameko.io/t/make-requests-to-download-file-in-url-with-nameko/492/4 "2019-09-03T12:53:46Z")

</div>

Thank you very much.

```
Traceback (most recent call last):
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py", line 682, in send
    r = adapter.send(request, **kwargs)
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
    chunked=chunked)
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 344, in _make_request
    self._validate_conn(conn)
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 843, in _validate_conn
    conn.connect()
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/urllib3/connection.py", line 370, in connect
    ssl_context=context)
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 355, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/eventlet/green/ssl.py", line 438, in wrap_socket
    return GreenSSLSocket(sock, *a, _context=self, **kw)
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/eventlet/green/ssl.py", line 76, in __new__
    *args, **kw
TypeError: wrap_socket() got an unexpected keyword argument '_context'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py", line 704, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py", line 704, in <listcomp>
    history = [resp for resp in gen] if allow_redirects else []
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py", line 258, in resolve_redirects
    **adapter_kwargs
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py", line 727, in send
    raise Exception(msg)
Exception: Error on session(). Cause : wrap_socket() got an unexpected keyword argument '_context' in /Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py L:682

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py", line 564, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py", line 727, in send
    raise Exception(msg)
Exception: Error on session(). Cause : Error on session(). Cause : wrap_socket() got an unexpected keyword argument '_context' in /Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py L:682 in /Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py L:704

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/nameko/containers.py", line 392, in _run_worker
    result = method(*worker_ctx.args, **worker_ctx.kwargs)
  File "./test-nameko.py", line 29, in do_post
    r = requests.get(url, allow_redirects=True)
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py", line 569, in request
    raise Exception(msg)
Exception: Error on request(). Cause : Error on session(). Cause : Error on session(). Cause : wrap_socket() got an unexpected keyword argument '_context' in /Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py L:682 in /Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py L:704 in /Users/tyu/project/etl_v3/venv/lib/python3.7/site-packages/requests/sessions.py L:564
127.0.0.1 - - [03/Sep/2019 14:50:21] "POST /post/my?type=url&url=https%3A%2F%2Fwww.python.org%2Fstatic%2Fimg%2Fpython-logo.png HTTP/1.1" 500 566 0.080115
```

---

<div class="post-metadata">

**Author:** ![yuut007](https://avatars.discourse-cdn.com/v4/letter/y/e9c0ed/32.png) [@yuut007](https://discourse.nameko.io/u/yuut007)\
**Post date:** [September 3, 2019, 12:57pm UTC](https://discourse.nameko.io/t/make-requests-to-download-file-in-url-with-nameko/492/5 "2019-09-03T12:57:42Z")

</div>

The python file is like above named “test-nameko.py”.

I run it in shell with command : nameko run test-nameko

And I do the simple http request with insomnia(with postman has the same error)

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/nameko/original/1X/5395bb76be48bc63ab428aed1f6394df1fb06a07.png)

---

<div class="post-metadata">

**Author:** ![Jakub\_Borys](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/jakub_borys/32/7_2.png) [@Jakub\_Borys](https://discourse.nameko.io/u/Jakub_Borys)\
**Post date:** [September 3, 2019, 2:07pm UTC](https://discourse.nameko.io/t/make-requests-to-download-file-in-url-with-nameko/492/6 "2019-09-03T14:07:46Z")

</div>

Hi @yuut007 unfortunately looks like eventlet library which is a nameko’s dependency is the root cause of the issue here as documented here: [https://github.com/eventlet/eventlet/issues/526](https://github.com/eventlet/eventlet/issues/526)

We have a test reproducing this issue and tracking it with: [https://github.com/nameko/nameko/pull/644](https://github.com/nameko/nameko/pull/644)

Is it possible for you to use Python 3.6 in meantime?

---

<div class="post-metadata">

**Author:** ![yuut007](https://avatars.discourse-cdn.com/v4/letter/y/e9c0ed/32.png) [@yuut007](https://discourse.nameko.io/u/yuut007)\
**Post date:** [September 3, 2019, 3:27pm UTC](https://discourse.nameko.io/t/make-requests-to-download-file-in-url-with-nameko/492/7 "2019-09-03T15:27:12Z")

</div>

Thanks a million. 😁 It works with python3.6. I am willing to tracking this problem with 3.7 in the future.
