Skip to content
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

[Question] How can I run HTTP.get in REPL with response? #898

Closed
hungpham3112 opened this issue Aug 2, 2022 · 4 comments
Closed

[Question] How can I run HTTP.get in REPL with response? #898

hungpham3112 opened this issue Aug 2, 2022 · 4 comments

Comments

@hungpham3112
Copy link

Environment:

  • Julia 1.7.3
  • HTTP.jl 1.2.0

I'm new with julia and try to use this package to learn about HTTP request.

In python REPL, I can type:

import requests
r = requests.get("your_url")
print(r) 

to take the data, but in Julia REPL when trying to type equivalent code, the REPL seems doing something and not respond to me and I have to cancel it.

using HTTP
r = HTTP.get("your_url")
println(r)
bandicam.2022-08-02.21-00-50-981.mp4
@hungpham3112 hungpham3112 changed the title [Question] How can I run HTTP.get in REPL [Question] How can I run HTTP.get in REPL with response? Aug 2, 2022
@quinnj
Copy link
Member

quinnj commented Aug 2, 2022

When you say you're "cancelling" the request, what do you mean? Are you entering ctrl + C to interrupt the HTTP.get call? Or is the error being thrown? Can you share the full error you're seeing?

@hungpham3112
Copy link
Author

When you say you're "cancelling" the request, what do you mean? Are you entering ctrl + C to interrupt the HTTP.get call? Or is the error being thrown? Can you share the full error you're seeing?

I entered Ctrl + c to interrupt it.

@quinnj
Copy link
Member

quinnj commented Aug 2, 2022

Hmm, I don't see any issues.

julia> using HTTP

julia> @time r = HTTP.get("http://dog.ceo/api/breeds/list/all")
  3.383419 seconds (12.76 M allocations: 633.043 MiB, 5.91% gc time, 94.27% compilation time)
HTTP.Messages.Response:
"""
HTTP/1.1 200 OK
Date: Tue, 02 Aug 2022 14:37:16 GMT
Content-Type: application/json
Content-Length: 948
Connection: keep-alive
X-Powered-By: PHP/7.3.31
Access-Control-Allow-Origin: *
Content-Encoding: gzip
Via: 1.1 varnish (Varnish/6.3), 1.1 varnish (Varnish/6.3)
Cache-Control: max-age=1800
X-Cache-Age: 2891
X-Cache-Hits: 826
X-Cache: HIT
Accept-Ranges: bytes
Age: 0
Vary: Accept-Encoding
CF-Cache-Status: DYNAMIC
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=EN0fbSCkHl3gKo%2FfyLiaGDyxbWAbmDkV3bwoHgaEafCKCAaVE8Tilu6%2BQt%2FXRqOQWLldegerKNPUMeqpXZcu%2BUJL%2FdfUjCnhNZUotxvDtm4j1hrWesP0WqK5"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Server: cloudflare
CF-RAY: 73478cf39fa65b7a-FRA
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

{"message":{"affenpinscher":[],"african":[],"airedale":[],"akita":[],"appenzeller":[],"australian":["shepherd"],"basenji":[],"beagle":[],"bluetick":[],"borzoi":[],"bouvier":[],"boxer":[],"brabancon":[],"briard":[],"buhund":["norwegian"],"bulldog":["boston","english","french"],"bullterrier":["staffordshire"],"cattledog":["australian"],"chihuahua":[],"chow":[],"clumber":[],"cockapoo":[],"collie":["border"],"coonhound":[],"corgi":["cardigan"],"cotondetulear":[],"dachshund":[],"dalmatian":[],"dane":["great"],"deerhound":["scottish"],"dhole":[],"dingo":[],"doberman":[],"elkhound":["norwegian"],"entlebucher":[],"eskimo":[],"finnish":["lapphund"],"frise":["bichon"],"germanshepherd":[],"greyhound":["italian"],"groenendael":[],"havanese":[],"hound":["afghan","basset","blood","english","ibizan","plott","walker"],"husky":[],"keeshond":[],"kelpie":[],"komondor":[],"kuvasz":[],"labradoodle":[],"labrador":[],"leonberg":[],"lhasa":[],"malamute":[],"malinois":[],"maltese":[],"mastiff":["bull","english

2130-byte body
"""

julia> @time r = HTTP.get("http://dog.ceo/api/breeds/list/all")
  0.090089 seconds (17.83 k allocations: 876.271 KiB, 8.44% compilation time)
HTTP.Messages.Response:
"""

Note that the 1st time HTTP.get is called, Julia has to compile the entire "request stack", which means it will take longer as it includes compilation time (see the use of the @time macro in my example above, which shows how long it took and what % of the time was compilation; the 2nd run was much faster w/ much less compilation time).

@hungpham3112
Copy link
Author

Hmm, I don't see any issues.

julia> using HTTP

julia> @time r = HTTP.get("http://dog.ceo/api/breeds/list/all")
  3.383419 seconds (12.76 M allocations: 633.043 MiB, 5.91% gc time, 94.27% compilation time)
HTTP.Messages.Response:
"""
HTTP/1.1 200 OK
Date: Tue, 02 Aug 2022 14:37:16 GMT
Content-Type: application/json
Content-Length: 948
Connection: keep-alive
X-Powered-By: PHP/7.3.31
Access-Control-Allow-Origin: *
Content-Encoding: gzip
Via: 1.1 varnish (Varnish/6.3), 1.1 varnish (Varnish/6.3)
Cache-Control: max-age=1800
X-Cache-Age: 2891
X-Cache-Hits: 826
X-Cache: HIT
Accept-Ranges: bytes
Age: 0
Vary: Accept-Encoding
CF-Cache-Status: DYNAMIC
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=EN0fbSCkHl3gKo%2FfyLiaGDyxbWAbmDkV3bwoHgaEafCKCAaVE8Tilu6%2BQt%2FXRqOQWLldegerKNPUMeqpXZcu%2BUJL%2FdfUjCnhNZUotxvDtm4j1hrWesP0WqK5"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Server: cloudflare
CF-RAY: 73478cf39fa65b7a-FRA
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

{"message":{"affenpinscher":[],"african":[],"airedale":[],"akita":[],"appenzeller":[],"australian":["shepherd"],"basenji":[],"beagle":[],"bluetick":[],"borzoi":[],"bouvier":[],"boxer":[],"brabancon":[],"briard":[],"buhund":["norwegian"],"bulldog":["boston","english","french"],"bullterrier":["staffordshire"],"cattledog":["australian"],"chihuahua":[],"chow":[],"clumber":[],"cockapoo":[],"collie":["border"],"coonhound":[],"corgi":["cardigan"],"cotondetulear":[],"dachshund":[],"dalmatian":[],"dane":["great"],"deerhound":["scottish"],"dhole":[],"dingo":[],"doberman":[],"elkhound":["norwegian"],"entlebucher":[],"eskimo":[],"finnish":["lapphund"],"frise":["bichon"],"germanshepherd":[],"greyhound":["italian"],"groenendael":[],"havanese":[],"hound":["afghan","basset","blood","english","ibizan","plott","walker"],"husky":[],"keeshond":[],"kelpie":[],"komondor":[],"kuvasz":[],"labradoodle":[],"labrador":[],"leonberg":[],"lhasa":[],"malamute":[],"malinois":[],"maltese":[],"mastiff":["bull","english

2130-byte body
"""

julia> @time r = HTTP.get("http://dog.ceo/api/breeds/list/all")
  0.090089 seconds (17.83 k allocations: 876.271 KiB, 8.44% compilation time)
HTTP.Messages.Response:
"""

Note that the 1st time HTTP.get is called, Julia has to compile the entire "request stack", which means it will take longer as it includes compilation time (see the use of the @time macro in my example above, which shows how long it took and what % of the time was compilation; the 2nd run was much faster w/ much less compilation time).

Thanks you for quick reply. Now I have better understanding of how HTTP.get works and now it runs normally. IDK why but in Windows some time it take more 15 seconds to run, so that the reason why I think it didn't respond.

I think I should close my question in here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants