-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change requests
to httpx
#208
Comments
Migrated recently HTTP requests from requests to aiohttp and looking forward to migrate some more requests to httpx this time. |
This would be awesome! I didn't have the chance to start tackling this issue, so you can go ahead 🚀 If you have any troubles running it locally, please let me know. We are moving to poetry and soon it will be way easier to configure your development env. |
That's great :)
Thanks, I keep that in mind. |
@tpiekarski are you working on this ? If not, I would be happy to take this up. 😄 |
Please go ahead, I am out of order for some time. Thanks 😊 |
@camilamaia on a quick overview of the issue I found requests to be used only in two files.
response = requests.request(
method,
url,
headers=self.headers,
params=self.params,
json=self.body,
allow_redirects=False,
)
import requests
Besides those, a couple of test files and of what I saw for tests
|
to remove imports and unused variables. I recommend: |
I tested changing Loading file ../examples/demo-api/.scanapi.yaml
Loading file ../examples/demo-api/scanapi.yaml
Writing documentation
Making request GET http://demo.scanapi.dev/api/health/
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/camilamaia/Library/Caches/pypoetry/virtualenvs/scanapi-KvDFA3Cq-py3.7/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/camilamaia/Library/Caches/pypoetry/virtualenvs/scanapi-KvDFA3Cq-py3.7/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/camilamaia/Library/Caches/pypoetry/virtualenvs/scanapi-KvDFA3Cq-py3.7/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/camilamaia/Library/Caches/pypoetry/virtualenvs/scanapi-KvDFA3Cq-py3.7/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/camilamaia/Library/Caches/pypoetry/virtualenvs/scanapi-KvDFA3Cq-py3.7/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/camilamaia/workspace/scanapi-org/scanapi/scanapi/__main__.py", line 62, in run
scan()
File "/Users/camilamaia/workspace/scanapi-org/scanapi/scanapi/scan.py", line 50, in scan
write_report(results)
File "/Users/camilamaia/workspace/scanapi-org/scanapi/scanapi/scan.py", line 63, in write_report
reporter.write(results)
File "/Users/camilamaia/workspace/scanapi-org/scanapi/scanapi/reporter.py", line 27, in write
content = render(template_path, context, has_external_template)
File "/Users/camilamaia/workspace/scanapi-org/scanapi/scanapi/template_render.py", line 13, in render
return chosen_template.render(**context)
File "/Users/camilamaia/Library/Caches/pypoetry/virtualenvs/scanapi-KvDFA3Cq-py3.7/lib/python3.7/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/Users/camilamaia/Library/Caches/pypoetry/virtualenvs/scanapi-KvDFA3Cq-py3.7/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/Users/camilamaia/Library/Caches/pypoetry/virtualenvs/scanapi-KvDFA3Cq-py3.7/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "/Users/camilamaia/workspace/scanapi-org/scanapi/scanapi/templates/html.jinja", line 408, in top-level template code
<p>{{request|curlify}}</p>
File "/Users/camilamaia/Library/Caches/pypoetry/virtualenvs/scanapi-KvDFA3Cq-py3.7/lib/python3.7/site-packages/curlify.py", line 25, in to_curl
if request.body:
AttributeError: 'Request' object has no attribute 'body' https://github.com/ofw/curlify/blob/master/curlify.py#L27 I only changed this to this: import httpx
....
response = httpx.request(
method,
url,
headers=self.headers,
params=self.params,
json=self.body,
allow_redirects=False,
) If I remove this line, everything works properly. About the differences between |
It seems
I think the best option is to use this enhanced (and updated) version of curlify https://github.com/marcuxyz/curlify2, otherwise it'll be needed to maybe fork (?) curlify or modify it's use inside this project. Line 23 in eba2ecd
|
@marcorichetta great catch. And in fact we are already using curlify2: https://github.com/scanapi/scanapi/blob/master/pyproject.toml#L23 Actually, @marcuxyz created this |
Oh, I read #208 (comment) and thought it was unresolved. So this issue is already solved by PR #330, right? |
@marcorichetta yes, exactly, the curl issue was solved. But we are not using |
@Pradhvan are you working on this ? If not, I would be happy to take this up |
no, feel free to take it. 😄 |
Change requests to httpx https://github.com/encode/httpx
Features
HTTPX builds on the well-established usability of
requests
, and gives you:Plus all the standard features of
requests
...The text was updated successfully, but these errors were encountered: