0

I am trying to GET response from a login page

Here is the code i tried to use

import http.client
url ="https://accounts.spotify.com/en/login?continue=https:%2F%2Fwww.spotify.com%2Fus%2Faccount%2Foverview%2F"
conn = http.client.HTTPSConnection(url,port=None)
conn.request("GET", "/")
r1 = conn.getresponse()
print(r1.status, r1.reason)

And this is the error i am getting

InvalidURL: nonnumeric port: '%2F%2Fwww.spotify.com%2Fus%2Faccount%2Foverview%2F'

The get url in my code contains : its reading data after that as PORT even after passing an extra argument port=None

Can someone help me out of this

  • https://stackoverflow.com/questions/14491814/httplib-invalidurl-nonnumeric-port Have you tried the second answer on this question with 17 votes? – Tim Jan 11 '19 at 20:29

1 Answers1

0

You have to just mention the host name and port in the constructor( Read more here). Rest of the request can be given in the request.You can view a lot of examples in the docs page.

You could pass the host name and rest of the request like this.

import http.client
url ="accounts.spotify.com"
conn = http.client.HTTPSConnection(url,port=None)
conn.request("GET", "/en/login?continue=https:%2F%2Fwww.spotify.com%2Fus%2Faccount%2Foverview%2F")
r1 = conn.getresponse()
print(r1.status, r1.reason)

Output

200 OK
Bitto
  • 7,937
  • 1
  • 16
  • 38
  • Thanks it worked perfectly I also have one more doubt.. If i want to enable auto redirect to turn on in python how should i do... in c# it would be request.redirect = true, in python how would it look like ? – Bhanu Teja Jan 11 '19 at 20:51
  • @BhanuTeja I believe it is set on by default. – Bitto Jan 11 '19 at 20:57
  • ok if its set by default how would i stop it ? Stopiing auto redirect, any extra arguments for that – Bhanu Teja Jan 11 '19 at 21:04
  • @BhanuTeja See this https://stackoverflow.com/questions/110498/is-there-an-easy-way-to-request-a-url-in-python-and-not-follow-redirects. – Bitto Jan 11 '19 at 21:12