Repository: encode/httpx

Issue:
Sync client fails on ASGI apps with unhelpful traceback
I tried using httpx with with an ASGI app in the way that was implied by the docs.  It throws an error that feels like a problem with httpx, as FastAPI is currently being used in production in other ways.  If you confirm that this is a bug in httpx, I'm willing (and probably capable) to fix it and submit a patch.

```
import httpx
from fastapi import FastAPI

app = FastAPI()


@app.get("/users/{user_id}")
async def read_user(user_id: str):
    return {'user_id': user_id}

with httpx.Client(app=app) as client:
    response = client.get("http://www.example.com/users/foo")
```

Throws the error:
```
Traceback (most recent call last):
  File "temp.py", line 12, in <module>
    response = client.get("http://www.example.com/users/foo")
  File "/Users/singletoned/.envs/testino/lib/python3.7/site-packages/httpx/_client.py", line 714, in get
    timeout=timeout,
  File "/Users/singletoned/.envs/testino/lib/python3.7/site-packages/httpx/_client.py", line 571, in request
    request, auth=auth, allow_redirects=allow_redirects, timeout=timeout,
  File "/Users/singletoned/.envs/testino/lib/python3.7/site-packages/httpx/_client.py", line 591, in send
    request, auth=auth, timeout=timeout, allow_redirects=allow_redirects,
  File "/Users/singletoned/.envs/testino/lib/python3.7/site-packages/httpx/_client.py", line 618, in send_handling_redirects
    request, auth=auth, timeout=timeout, history=history
  File "/Users/singletoned/.envs/testino/lib/python3.7/site-packages/httpx/_client.py", line 654, in send_handling_auth
    response = self.send_single_request(request, timeout)
  File "/Users/singletoned/.envs/testino/lib/python3.7/site-packages/httpx/_client.py", line 678, in send_single_request
    response = dispatcher.send(request, timeout=timeout)
  File "/Users/singletoned/.envs/testino/lib/python3.7/site-packages/httpx/_dispatch/wsgi.py", line 90, in send
    result = self.app(environ, start_response)
TypeError: __call__() missing 1 required positional argument: 'send'
```


Discussion:
Hi Ed!

This is actually expected behavior. You’re trying to use an ASGI app with the sync client — this is not supported as the sync client only supports WSGI.

So you should use an AsyncClient with your FastAPI app. :)

I have personally got bitten by this in the past too, so we should probably do something to improve the UX here. Maybe checking the signature of `app` in `WSGIDispatcher, and raising à helpful error message if it doesn’t look like a WSGI app (ie à callable with 2 parameters).

If you'd like to give this a try, please feel free to 😄 
I went ahead and updated the issue description.

Note that we *shouldn't* support calling async apps from the sync client (eg running the app in a new event loop) because this kind of bridging approach has bitten us in the past. We should encourage a strict separation of use cases (which is why `app` on the sync Client must be WSGI, while on the async client it must be ASGI).

Resolving patch:
diff --git a/httpx/_client.py b/httpx/_client.py
--- a/httpx/_client.py
+++ b/httpx/_client.py
@@ -426,7 +426,7 @@ class Client(BaseClient):
     request URLs.
     * **dispatch** - *(optional)* A dispatch class to use for sending requests
     over the network.
-    * **app** - *(optional)* An ASGI application to send requests to,
+    * **app** - *(optional)* An WSGI application to send requests to,
     rather than sending actual network requests.
     * **trust_env** - *(optional)* Enables or disables usage of environment
     variables for configuration.


Test patch: