Hi, I'm trying to dynamically build a url in python and have tried using:
#file.py import json import requests from urllib.parse import urljoin baseUrl = " http://data.parliament.uk/membersdataplatform/services/mnis/members/query" search_criteria = "House=Commons" outputs = "Constituencies" headers = {"content-type": "application/json"} *""" so the resulting url: resultUrl should be * http://data.parliament.uk/membersdataplatform/services/mnis/members/query/House=Commons/Constituencies *"""* *result = search_criteria + outputs* *resultUrl = urljoin(baseUrl + result)* *"""However when I do the following:"""* *r = requests.get(resultUrl, headers=headers)* *r.encoding = "utf-8"* *dump = r.text* *members = json.loads(test[1:])* *""" I get a JSONdecodeError which complains about the first character in r.text being a <. The problem is if I use the url as is:"""* *r = requests.get("* http://data.parliament.uk/membersdataplatform/services/mnis/members/query/House=Commons/Constituencies", headers) """ it works I would like to give the user the option to switch between House=Commons and House=Lords but can't yet because I haven't figured out how to dynamically build url""" What am I doing wrong? Hoping that someone could help me. Many thanks, On 19 June 2017 at 17:00, <tutor-requ...@python.org> wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > Today's Topics: > > 1. Re: Coming from R, what's a good IDE editor? I've tried > PyCharm and Spyder (C W) > > > ---------- Forwarded message ---------- > From: C W <tmrs...@gmail.com> > To: Cameron Simpson <c...@zip.com.au> > Cc: Mats Wichmann <m...@wichmann.us>, tutor@python.org > Bcc: > Date: Sun, 18 Jun 2017 13:07:07 -0400 > Subject: Re: [Tutor] Coming from R, what's a good IDE editor? I've tried > PyCharm and Spyder > I come back to report that after trying it myself. Rodeo is the winner! > Spyder came close. > > There's even a post on moving the layouts around just like RStudio. > http://discuss.yhat.com/t/move-around-the-layout/43 > > I hope they implement that soon. Thanks everyone for your advice! > > On Thu, Jun 8, 2017 at 9:00 PM, Cameron Simpson <c...@zip.com.au> wrote: > > > On 02Jun2017 18:14, Mats Wichmann <m...@wichmann.us> wrote: > > > >> Sadly, vim, which is The Best Editor Ever (see 23 million flamewars for > >> why such statement can only be a feeble attempt at humor, not reality), > >> is now trying to behave like an IDE, and it's doing things badly wrong. > >> For example, if I type import in a "from" line, it helpfully inserts the > >> word import... meaning those end up with syntax errors, "from foo import > >> import bar". I don't know who is responsible for that idiocy and > >> haven't taken the time to figure out how to shut off the misbehavior. > >> > > > > I'm sure it can be turned off; mine doesn't do this. I also turned off > the > > auto-comment-continuation. > > > > Anyway, somewhat off topic. > > > > -- Cameron Simpson <c...@zip.com.au> > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription options: > > https://mail.python.org/mailman/listinfo/tutor > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > https://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor