{"action":"created","issue":{"url":"https://api.github.com/repos/theelous3/asks/issues/85","repository_url":"https://api.github.com/repos/theelous3/asks","labels_url":"https://api.github.com/repos/theelous3/asks/issues/85/labels{/name}","comments_url":"https://api.github.com/repos/theelous3/asks/issues/85/comments","events_url":"https://api.github.com/repos/theelous3/asks/issues/85/events","html_url":"https://github.com/theelous3/asks/issues/85","id":362850794,"node_id":"MDU6SXNzdWUzNjI4NTA3OTQ=","number":85,"title":"Weird behavior with Session.get and streaming?","user":{"login":"sztomi","id":240594,"node_id":"MDQ6VXNlcjI0MDU5NA==","avatar_url":"https://avatars1.githubusercontent.com/u/240594?v=4","gravatar_id":"","url":"https://api.github.com/users/sztomi","html_url":"https://github.com/sztomi","followers_url":"https://api.github.com/users/sztomi/followers","following_url":"https://api.github.com/users/sztomi/following{/other_user}","gists_url":"https://api.github.com/users/sztomi/gists{/gist_id}","starred_url":"https://api.github.com/users/sztomi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sztomi/subscriptions","organizations_url":"https://api.github.com/users/sztomi/orgs","repos_url":"https://api.github.com/users/sztomi/repos","events_url":"https://api.github.com/users/sztomi/events{/privacy}","received_events_url":"https://api.github.com/users/sztomi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-22T11:44:55Z","updated_at":"2018-09-22T12:04:33Z","closed_at":null,"author_association":"NONE","body":"I might be doing something wrong, but I can't figure this out.\r\n\r\nI have the following code that talks to a pypi simple API (think `self.session.base_location` being set to `https://pypi.org/simple/`):\r\n\r\n```python\r\n  async def get(self, path, stream=False):\r\n    self.log.debug(f\"GET {path}\")\r\n    self.log.debug(f\"stream = {stream}\")\r\n    return await self.session.get(path=path, auth=self.auth, stream=stream)\r\n```\r\n\r\nNow, I'm doing this:\r\n\r\n```python\r\nawait api.get(\"/requests\")   # (1)\r\n```\r\n\r\nI just added the `stream` parameter with the default value of `False`. And suddenly my code expecting a `Response` breaks because the return value is now `StreamResponse` (despite `stream` being `False`). My log output:\r\n\r\n```\r\n2018-09-22 13:41:51,433   bib.installer.installer  DEBUG    - Base URL: https://pypi.org/simple\r\n2018-09-22 13:41:51,433   bib.installer.installer  DEBUG    - Getting metadata of requests\r\n2018-09-22 13:41:51,433   bib.api.legacy           DEBUG    - GET /requests\r\n2018-09-22 13:41:51,433   bib.api.legacy           DEBUG    - stream = False\r\nTraceback (most recent call last):\r\n  File \"/home/tamas/.local/share/virtualenvs/bib-wgx9oSkl/bin/bib\", line 11, in <module>\r\n    load_entry_point('bib', 'console_scripts', 'bib')()\r\n  File \"/home/tamas/.local/share/virtualenvs/bib-wgx9oSkl/lib/python3.7/site-packages/trio_click/core.py\", line 748, in __call__\r\n    return trio.run(main,*args)\r\n  File \"/home/tamas/.local/share/virtualenvs/bib-wgx9oSkl/lib/python3.7/site-packages/trio/_core/_run.py\", line 1328, in run\r\n    raise runner.main_task_outcome.error\r\n  File \"/home/tamas/.local/share/virtualenvs/bib-wgx9oSkl/lib/python3.7/site-packages/trio_click/core.py\", line 720, in main\r\n    rv = await self.invoke(ctx)\r\n  File \"/home/tamas/.local/share/virtualenvs/bib-wgx9oSkl/lib/python3.7/site-packages/trio_click/core.py\", line 1117, in invoke\r\n    return await _process_result(await sub_ctx.command.invoke(sub_ctx))\r\n  File \"/home/tamas/.local/share/virtualenvs/bib-wgx9oSkl/lib/python3.7/site-packages/trio_click/core.py\", line 936, in invoke\r\n    return await ctx.invoke(self.callback, **ctx.params)\r\n  File \"/home/tamas/.local/share/virtualenvs/bib-wgx9oSkl/lib/python3.7/site-packages/trio_click/core.py\", line 560, in invoke\r\n    rv = await rv\r\n  File \"/home/tamas/projects/bib/bib/cli.py\", line 19, in install\r\n    await installer.fetch_pkg(pkg)\r\n  File \"/home/tamas/projects/bib/bib/installer/installer.py\", line 65, in fetch_pkg\r\n    url = await self._fetch_metadata(pkg)\r\n  File \"/home/tamas/projects/bib/bib/installer/installer.py\", line 37, in _fetch_metadata\r\n    releases = await self.api.get_releases(pkg)\r\n  File \"/home/tamas/projects/bib/bib/api/legacy.py\", line 22, in get_releases\r\n    data = await trio.run_sync_in_worker_thread(parse_simple_index, resp.text)\r\nAttributeError: 'StreamResponse' object has no attribute 'text'\r\n```\r\n\r\nHowever, if I do this:\r\n\r\n```python\r\n  async def get(self, path, stream=False):\r\n    self.log.debug(f\"GET {path}\")\r\n    self.log.debug(f\"stream = {stream}\")\r\n    if stream:\r\n      return await self.session.get(path=path, auth=self.auth, stream=stream)\r\n    return await self.session.get(path=path, auth=self.auth)\r\n```\r\n\r\ni.e. not pass `stream` if it's false, the line marked with (1) works as expected and this error goes away. \r\n\r\nUnlike the code which previously used `asks.get` for a streaming response. I changed it to use the above function (to reuse the session). Now, even though I pass `stream=True` in this case, I still get `Response`/`bytes` instead of `StreamResponse`:\r\n\r\n```python\r\nwhl_resp = await self.api.get(url, stream=True)  # (2)\r\nfname = url.split(\"/\")[-1]\r\noutput_name = trio.Path(self.target_dir / fname)\r\nself.log.debug(type(whl_resp))\r\nself.log.debug(type(whl_resp.body))\r\n```\r\n\r\nMy log output for this second code block:\r\n\r\n```\r\n2018-09-22 13:34:53,307   bib.api.legacy           DEBUG    - GET /requests-2.19.1-py2.py3-none-any.whl\r\n2018-09-22 13:34:53,307   bib.api.legacy           DEBUG    - stream = True\r\n2018-09-22 13:34:53,592   bib.installer.installer  DEBUG    - <class 'asks.response_objects.Response'>\r\n2018-09-22 13:34:53,592   bib.installer.installer  DEBUG    - <class 'bytes'>\r\n```\r\n\r\nAs a result, my code that follows this [example](https://asks.readthedocs.io/en/latest/idioms.html#handling-response-body-content-downloads-etc) for streamed downloads breaks (because the body is `bytes`).\r\n\r\nI would expect the following behavior:\r\n\r\n  * If I pass `stream=True` to `Session.get`, the response becomes a `StreamResponse` (regardless of actual streaming taking place)\r\n  * If I pass `stream=False` or don't pass `stream` at all, the response is `Response` and body is `bytes` \r\n\r\nAm I doing something wrong or is this a bug?\r\n"},"comment":{"url":"https://api.github.com/repos/theelous3/asks/issues/comments/423739510","html_url":"https://github.com/theelous3/asks/issues/85#issuecomment-423739510","issue_url":"https://api.github.com/repos/theelous3/asks/issues/85","id":423739510,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMzczOTUxMA==","user":{"login":"theelous3","id":19316042,"node_id":"MDQ6VXNlcjE5MzE2MDQy","avatar_url":"https://avatars3.githubusercontent.com/u/19316042?v=4","gravatar_id":"","url":"https://api.github.com/users/theelous3","html_url":"https://github.com/theelous3","followers_url":"https://api.github.com/users/theelous3/followers","following_url":"https://api.github.com/users/theelous3/following{/other_user}","gists_url":"https://api.github.com/users/theelous3/gists{/gist_id}","starred_url":"https://api.github.com/users/theelous3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theelous3/subscriptions","organizations_url":"https://api.github.com/users/theelous3/orgs","repos_url":"https://api.github.com/users/theelous3/repos","events_url":"https://api.github.com/users/theelous3/events{/privacy}","received_events_url":"https://api.github.com/users/theelous3/received_events","type":"User","site_admin":false},"created_at":"2018-09-22T12:04:33Z","updated_at":"2018-09-22T12:04:33Z","author_association":"OWNER","body":"This sounds buggy. Time for coffee."}}
{"actor":{"display_login":"theelous3"}}