Andrew Thank you, that resolves the POSTing problem. I'm getting an error on the query, but I'll try and resolve that myself!
Cheers Andy -----Original Message----- From: Andrew Hankinson <andrew.hankinson@rism.digital> Sent: 17 December 2024 10:23 To: users@solr.apache.org Subject: Re: Problem with POST in python code CAUTION: This email originated from outside of the organisation. Do not click links or open attachments unless you recognise the sender and believe the content to be safe. You're not actually POSTing the data. The requests module is a lot easier than using the urllib module. https://requests.readthedocs.io/en/latest/ r = requests.post('http://localhost:8983/solr/films/query', data={"query":"*:*"}) print(r.json()) This should set all the appropriate headers as well. -Andrew > On 17 Dec 2024, at 10:53, Macfarlane, Andrew > <a.macfarlan...@city.ac.uk.INVALID> wrote: > > Hi > > I’m trying to connect with a SOLR server, using the POST methods in python, > but I’m getting an error. > > This is the code (full file is attached): > > #Form the URL > searchURL = 'http://localhost:8983/solr/films/query' > > querytext = {"json":{"query":"shane"}} #querytext = {"query":"*:*"} > > #form the query > query = urllib.parse.urlencode(querytext).encode('utf-8') > > #get data from the server > try: > connection = urllib.request.Request(searchURL, query) except > Exception as error: > print("Connection failed: ", error) > exit() > > connection.add_header('Content-Type', 'application/json') > > #extract data from the connection made > try: > response = urllib.request.urlopen(connection) > except Exception as error: > print("No response returned: ", error) > exit() > > Reponse is: > > solr-9.6.1>python python-apps\film-POST.py No response returned: HTTP > Error 400: Bad Request > > Logging on the server gives: > > <image001.png> > I’ve attempted many ways resolving this to address the issue, but with no > success. Can someone help me please? > > Cheers > Andy > > --------------------------------------------------