goepsilongo has quit [Quit: Konversation terminated!]
jackiiilong__ has quit [Ping timeout: 240 seconds]
canton7 has joined #ruby
jenrzzz has joined #ruby
jenrzzz has quit [Ping timeout: 252 seconds]
ur5us has quit [Ping timeout: 250 seconds]
evdubs_ has joined #ruby
<User458764>
Hi, is there an example script which contains all ruby syntax?
evdubs has quit [Ping timeout: 260 seconds]
rubydoc has joined #ruby
<jhass>
not aware of any, the rubykoans might get you kinda close but probably lack things like case pattern matching
postmodern has quit [Quit: Leaving]
phaul has joined #ruby
gearnode has quit [Ping timeout: 250 seconds]
<User458764>
Thanks I will look at it
ChmEarl has joined #ruby
gearnode has joined #ruby
vasanth has joined #ruby
phaul has quit [Ping timeout: 265 seconds]
phaul has joined #ruby
rubydoc_ has joined #ruby
rubydoc has quit [Remote host closed the connection]
dpl has quit [Ping timeout: 240 seconds]
jamees has quit [Quit: Connection closed]
jenrzzz has joined #ruby
Hess has quit [Ping timeout: 250 seconds]
<isene>
I would be grateful for a helping and in debugging a Net:HTTP request. Code, output and short problem description here: https://dpaste.org/j7Cy
dpl has joined #ruby
jenrzzz has quit [Ping timeout: 252 seconds]
<havenwood>
isene: Looks like you mean to be setting a header but instead you're passing params.
<havenwood>
isene: Check docs for how to set headers.
<havenwood>
Oh, right, Net::HTTP.get — never mind about headers.
jenrzzz has joined #ruby
jenrzzz has quit [Ping timeout: 240 seconds]
<isene>
Everything is working - except that Ruby adds that pesky ":80" (for the port) at the end of the URI. If I could only remove that, it would be fully functioning
jenrzzz has joined #ruby
<isene>
jhass: wrapping that URL into URI() makes no difference - the ":80" is still added to the end of the URL
<jhass>
are you sure? Can you show your current code and exact error message again please? :)
<isene>
jhass: Well... how then do I fix it (meaning just removing the ":80")?
<jhass>
well yes turning the URI back into a string of course makes it a string again...
<isene>
jhass: Yes - but it does complain about it not being a string in the first try
<jhass>
try just .get(URI(...)) without the headers for a test
TorpedoSkyline has quit [Quit: Konversation terminated!]
<isene>
jhass: Now this was the reason why I had to send along a user-agent in the first place, because met.no refuses to recognize the generic header: https://dpaste.org/oJoc
<jhass>
But you can see it no longer "adds the :80" ;)
<jhass>
so it's actually a step further
<jhass>
it looks like Ruby 2.7 does not allow setting headers via the class methods
<jhass>
See "Setting Headers" in the documentation
<isene>
jhass: It did work without any specific UA until last week or so when met.no decided to do some code change that stopped the use of a generic UA
<jhass>
I'm not contesting that the service needs the header set
<isene>
jhass: No, no - I'm not suggesting you are :-)
<isene>
jhass: I don't quite get how to add the UA in the header from that part of the doc (Setting Headers)
<jhass>
it's a complete example so I'm not sure what to say to a generic question like this :)
<isene>
The problem with the "Setting Headers" section is that it does the GET call before setting any header like a UA
yxhuvud has quit [Remote host closed the connection]
<jhass>
isene: the example set's the "If-modified-Since" header
<jhass>
the request does not happen until the http.request(req) line
<isene>
jhass: So how do I specifically set an UA?
<jhass>
like in the example, just instead of setting the "If-Modified-Since" header set the "User-Agent" header
<adam12>
isene: I just don’t get how the source you linked raises that stacktrace.
<adam12>
isene: You’re not calling any JSON parsing methods. Is Net::HTTP doing that? I’ve never seen that behavior.
<isene>
adam12: It's part of a larger project - the astropanel (https://github.com/isene/astropanel/blob/main/astropanel.rb#L678) - lines 679-681 doesn't work anymore as met.no rejects a call with the generic "Ruby" UA. I therefore have to do mental gymnastics to add a simple user-agent to the get request - which turns out to be insanely complex.
<isene>
jhass: Where in my code do I set that?
jenrzzz has joined #ruby
<jhass>
did you look at the "HTTPS" section of the documentation?
<isene>
jhass: Did this without any change whatsoever: json = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|
Dwarf has left #ruby [#ruby]
<jhass>
There's a change :)
<jhass>
print the response body if you need a less subtle hint
jenrzzz has quit [Ping timeout: 240 seconds]
<isene>
With or without the use_ssl, I get:
<isene>
/usr/lib/ruby/2.7.0/json/common.rb:156:in `initialize': no implicit conversion of Net::HTTPForbidden into String (TypeError)
<jhass>
Is HTTPForbidden the same as HTTPBadRequest?
<jhass>
I'd say it's not ;)
<adam12>
The docs for net/http seem kind of horrible.
<adam12>
Actually, horrible is a poor word.
<jhass>
also take another look at the setting headers example, what kind of object do you get returned from http.request?
<isene>
adam12: Yes, it sucks
<adam12>
The square bracket setter from Net::HTTPHeader is basically completely hidden unless you poke around for it. I find that the most annoying part of rdoc.
<jhass>
the docs are not very good but that also has to do with the API of net/http being not very good. It's continously improved a little but the base is just... well there's a reason for so many http library gems :D
<adam12>
Yes, it’s no surprise httparty basically ballooned in usage back in the 2000’s.
<havenwood>
Net::HTTP wrappers party too hard.
<jhass>
yeah especially since that was before we had any of the class helper methods and everything had to use the .start interface
<adam12>
I’d love to see a Rack-like API for HTTP clients (not Faraday), because I’m _tired_ of having a half-dozen HTTP clients in a larger project.
<isene>
This is all I want to do - to get f*cking Net::HTTP to give me that json output.
<jhass>
the requests headers your browser sends are quite different to those you send
<jhass>
(there's a reason the server rejects you these requests btw so I'm not just gonna give you copy paste circumvention here without a learning experience, in case you wonder)
<isene>
jhass: I know - but the ONLY new requirement is that I supply a UA. It's a tiny teenie-weenie addition that shouldn't require a whole new sky scraper of complexity
<jhass>
Ruby was sending a user agent before, so the requirement is a bit more subtle than "set a user agent"
<isene>
jhass: I don't need a learning experience. I need this to work. That's all.
budonyc has joined #ruby
<jhass>
then pay somebody to do it :)
<havenwood>
or learn.
kaivai_ has joined #ruby
<isene>
What's you paypal account. How much?
vasanth has quit [Ping timeout: 268 seconds]
<jhass>
I'm happy with my current job, no interest, thanks :)
<isene>
jhass: But do you actually have the answer?
kaivai has quit [Ping timeout: 246 seconds]
<jhass>
Sure. In fact you have it to, I made it work by copy pasting from something you previously had already and changed since
<isene>
So, why not just give me the answer?
yxhuvud has quit [Remote host closed the connection]
<jhass>
actually that version is still violating their ToS