pdb, PUT, python, fail - or maybe stupidity...
Hi gents, ladies, Arnold asked me to post this to the list, maybe I'm just doing something very wrong. If anybody has a hint (or experience), that could potentially make me happy :-) Elmar. === I'm trying to update a net object from python, using the requests library with the peeringdb RESTful API, essentially doing a PUT operation.. Just in case I'm too stupid to ... here's the whole she-bang ---------- What I send: import request URL = 'https://isc-apiuser:********@peeringdb.com/api/net/12085' dict_headers = { "Accept" : "application/json", "Content-Type" : "application/json", } dict_changes = { "irr_as_set" : "AS3557", } request.put(url=URL, data=dict_changes, headers=dict_headers) ---------- What I get: 400 Client Error: Bad Request for url: https://isc-apiuser:************@peeringdb.com/api/net/12085 === Yes, the user has "update" rights to all net objects (got the 403 when that was not the case, so auth works)
It is probably just because it is redirecting through proofpoint, which mangles the URL with junk, change your URL to just be URL = 'https://api-user.......@peeringdb.com/api/net/12085' Mike Simkins ▪ Technical Architect ▪ Core Network Architecture and Engineering ▪ Sungard Availability Services Lighterman House, 3 Clove Crescent, London E14 2BB ▪ Office: +44 (0) 20 8080 8060 / +1 720-833-7731 ▪ Mobile: +44 (0) 7710 677486 ▪ mike.simkins@sungardas.com ▪ www.sungardas.com Sungard Availability Services Service Desk ▪ (EMEA) +44 (0) 800 279 9166 ▪ (US) +1 800 441 1181 Upcoming Vacation: None Scheduled Top 5 Strengths: RESPONSIBILITY – ADAPTABILITY – DELIBERATIVE – BELIEF – RESTORATIVE CONFIDENTIALITY: This e-mail (including any attachments) may contain confidential, proprietary and privileged information, and unauthorized disclosure or use is prohibited. If you received this e-mail in error, please notify the sender and delete this e-mail from your system. -----Original Message----- From: Pdb-tech <pdb-tech-bounces@lists.peeringdb.com> On Behalf Of Elmar K. Bins Sent: 28 January 2020 11:05 To: pdb-tech@lists.peeringdb.com Subject: [PDB Tech] pdb, PUT, python, fail - or maybe stupidity... Hi gents, ladies, Arnold asked me to post this to the list, maybe I'm just doing something very wrong. If anybody has a hint (or experience), that could potentially make me happy :-) Elmar. === I'm trying to update a net object from python, using the requests library with the peeringdb RESTful API, essentially doing a PUT operation.. Just in case I'm too stupid to ... here's the whole she-bang ---------- What I send: import request URL = 'https://urldefense.proofpoint.com/v2/url?u=https-3A__isc-2Dapiuser-3A-2A-2A-... ' dict_headers = { "Accept" : "application/json", "Content-Type" : "application/json", } dict_changes = { "irr_as_set" : "AS3557", } request.put(url=URL, data=dict_changes, headers=dict_headers) ---------- What I get: 400 Client Error: Bad Request for url: https://urldefense.proofpoint.com/v2/url?u=https-3A__isc-2Dapiuser-3A-2A-2A-... === Yes, the user has "update" rights to all net objects (got the 403 when that was not the case, so auth works) _______________________________________________ Pdb-tech mailing list Pdb-tech@lists.peeringdb.com https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.peeringdb.com_cgi...
Hi Mike, mike.simkins@sungardas.com (Mike Simkins) wrote:
It is probably just because it is redirecting through proofpoint, which mangles the URL with junk, change your URL to just be
That's of course what the URL looks like. URL mangling in mailing lists... what has the world come to? Elmar.
-----Original Message----- From: Pdb-tech <pdb-tech-bounces@lists.peeringdb.com> On Behalf Of Elmar K. Bins Sent: 28 January 2020 11:05 To: pdb-tech@lists.peeringdb.com Subject: [PDB Tech] pdb, PUT, python, fail - or maybe stupidity...
Hi gents, ladies,
Arnold asked me to post this to the list, maybe I'm just doing something very wrong. If anybody has a hint (or experience), that could potentially make me happy :-)
Elmar.
===
I'm trying to update a net object from python, using the requests library with the peeringdb RESTful API, essentially doing a PUT operation..
Just in case I'm too stupid to ... here's the whole she-bang
---------- What I send:
import request
URL = 'https://urldefense.proofpoint.com/v2/url?u=https-3A__isc-2Dapiuser-3A-2A-2A-... '
dict_headers = { "Accept" : "application/json", "Content-Type" : "application/json", }
dict_changes = { "irr_as_set" : "AS3557", }
request.put(url=URL, data=dict_changes, headers=dict_headers)
---------- What I get:
400 Client Error: Bad Request for url: https://urldefense.proofpoint.com/v2/url?u=https-3A__isc-2Dapiuser-3A-2A-2A-...
I know the list mangles URLs 😊. I actually had an similar issue with this because an internal proxy (that I was not aware of) did something similar to this to my request, and when I went to a DMZ issue cleared up. Apologies, not enough coffee this morning. -----Original Message----- From: Pdb-tech <pdb-tech-bounces@lists.peeringdb.com> On Behalf Of Elmar K. Bins Sent: 28 January 2020 11:22 To: pdb-tech@lists.peeringdb.com Subject: Re: [PDB Tech] pdb, PUT, python, fail - or maybe stupidity... Hi Mike, mike.simkins@sungardas.com (Mike Simkins) wrote:
It is probably just because it is redirecting through proofpoint, which mangles the URL with junk, change your URL to just be
URL = 'https://urldefense.proofpoint.com/v2/url?u=https-3A__api-2Duser.......-40pee... '
That's of course what the URL looks like. URL mangling in mailing lists... what has the world come to? Elmar.
-----Original Message----- From: Pdb-tech <pdb-tech-bounces@lists.peeringdb.com> On Behalf Of Elmar K. Bins Sent: 28 January 2020 11:05 To: pdb-tech@lists.peeringdb.com Subject: [PDB Tech] pdb, PUT, python, fail - or maybe stupidity...
Hi gents, ladies,
Arnold asked me to post this to the list, maybe I'm just doing something very wrong. If anybody has a hint (or experience), that could potentially make me happy :-)
Elmar.
===
I'm trying to update a net object from python, using the requests library with the peeringdb RESTful API, essentially doing a PUT operation..
Just in case I'm too stupid to ... here's the whole she-bang
---------- What I send:
import request
URL = 'https://urldefense.proofpoint.com/v2/url?u=https-3A__isc-2Dapiuser-3A-2A-2A-... '
dict_headers = { "Accept" : "application/json", "Content-Type" : "application/json", }
dict_changes = { "irr_as_set" : "AS3557", }
request.put(url=URL, data=dict_changes, headers=dict_headers)
---------- What I get:
400 Client Error: Bad Request for url: https://urldefense.proofpoint.com/v2/url?u=https-3A__isc-2Dapiuser-3A- 2A-2A-2A-2A-2A-2A-2A-2A-2A-2A-2A-2A-40peeringdb.com_api_net_12085&d=Dw IGaQ&c=gYbc-GKV5BQa9zrq1GFCVg&r=S1PZn0PYDDYtiCW2fix2C1ZHo8KzLAckyehxqI 4wl20&m=Bj5gpSKHmwyokLiDwTrX0jXf9zpTc2-BOA0tVEB24-I&s=Y34j7X3mWgmw72Iy pQKJtOk-oN-Zwlz-GnIqByXPMbc&e=
_______________________________________________ Pdb-tech mailing list Pdb-tech@lists.peeringdb.com https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.peeringdb.com_cgi...
PUT needs you supply values for all required fields not just fields you want to change, i am guessing that's what is the issue here. If you check the content of the 400 response you are getting it should tell you which other fields it wants you to submit in your payload (or any other reason why it's failing) PATCH would be the method for partial updates like you are trying to do, but is currently not enabled/supported on the api. Stefan On 28/01/2020 13.05, Elmar K. Bins wrote:
Hi gents, ladies,
Arnold asked me to post this to the list, maybe I'm just doing something very wrong. If anybody has a hint (or experience), that could potentially make me happy :-)
Elmar.
===
I'm trying to update a net object from python, using the requests library with the peeringdb RESTful API, essentially doing a PUT operation..
Just in case I'm too stupid to ... here's the whole she-bang
---------- What I send:
import request
URL = 'https://isc-apiuser:********@peeringdb.com/api/net/12085'
dict_headers = { "Accept" : "application/json", "Content-Type" : "application/json", }
dict_changes = { "irr_as_set" : "AS3557", }
request.put(url=URL, data=dict_changes, headers=dict_headers)
---------- What I get:
400 Client Error: Bad Request for url: https://isc-apiuser:************@peeringdb.com/api/net/12085
===
Yes, the user has "update" rights to all net objects (got the 403 when that was not the case, so auth works) _______________________________________________ Pdb-tech mailing list Pdb-tech@lists.peeringdb.com https://lists.peeringdb.com/cgi-bin/mailman/listinfo/pdb-tech
Hi Stefan, stefan@20c.com (Stefan Pratter) wrote:
PUT needs you supply values for all required fields not just fields you want to change, i am guessing that's what is the issue here.
Thanks for the insight; I tried submitting the entire object, still getting the same response.
If you check the content of the 400 response you are getting it should tell you which other fields it wants you to submit in your payload (or any other reason why it's failing)
I don't seem to get more information than "Client Error: Bad request"; I'll try and find out if there's more somewhere that will show me why it fails, but so far I've not been lucky.. - Elmar.
I don't seem to get more information than "Client Error: Bad request"; I'll try and find out if there's more somewhere that will show me why it fails, but so far I've not been lucky..
If you're using python requests to handle your requests it'd be the json() method on the result returned by the put() call r = put(..) print(r.json())
Thanks for the insight; I tried submitting the entire object, still getting the same response.
grab the net dict as it is from https://www.peeringdb.com/api/net/12085?pretty&depth=0 depth 0 is important here so you don't expand relationships - also make sure you don't grab the root dict or the data list, just the net dict itself. try sending that with your put request (modify the field you want to modify) If it's still failing with that it's some other issue and the content of the 400 response would be vital :) On 28/01/2020 14.13, Elmar K. Bins wrote:
Hi Stefan,
stefan@20c.com (Stefan Pratter) wrote:
PUT needs you supply values for all required fields not just fields you want to change, i am guessing that's what is the issue here.
Thanks for the insight; I tried submitting the entire object, still getting the same response.
If you check the content of the 400 response you are getting it should tell you which other fields it wants you to submit in your payload (or any other reason why it's failing)
I don't seem to get more information than "Client Error: Bad request"; I'll try and find out if there's more somewhere that will show me why it fails, but so far I've not been lucky..
- Elmar. _______________________________________________ Pdb-tech mailing list Pdb-tech@lists.peeringdb.com https://lists.peeringdb.com/cgi-bin/mailman/listinfo/pdb-tech
Hi Stefan, stefan@20c.com (Stefan Pratter) wrote:
print(r.json())
Ah, I've been looking for that; now it just tells me... {'meta': {'error': 'JSON parse error - Expecting value: line 1 column 1 (char 0)'}} Ok, I've now tried putting data=...: - Only the changes as a simple <dict>. - The entire object (from data[0]) as a simple <dict>. - The entire object (from data[0]) as {'data': [ <dict> ] } - The entire object (from data[0]) plus empty meta as {'data': [ <dict> ], 'meta': {} } I'm always getting the JSON parse error. Am I missing a conversion step somewhere? json.dumps() looks alright in all cases. - Elmar.
may need to json encode it yourself before you send it off, don't recall tho so assuming `data` is your net dict put(data=json.dumps(data)) The server error means it's having trouble parsing json from the data you currently send and failing at the first character it encounters. On 28/01/2020 14.48, Elmar K. Bins wrote:
Hi Stefan,
stefan@20c.com (Stefan Pratter) wrote:
print(r.json())
Ah, I've been looking for that; now it just tells me... {'meta': {'error': 'JSON parse error - Expecting value: line 1 column 1 (char 0)'}}
Ok, I've now tried putting data=...:
- Only the changes as a simple <dict>. - The entire object (from data[0]) as a simple <dict>. - The entire object (from data[0]) as {'data': [ <dict> ] } - The entire object (from data[0]) plus empty meta as {'data': [ <dict> ], 'meta': {} }
I'm always getting the JSON parse error. Am I missing a conversion step somewhere?
json.dumps() looks alright in all cases.
- Elmar. _______________________________________________ Pdb-tech mailing list Pdb-tech@lists.peeringdb.com https://lists.peeringdb.com/cgi-bin/mailman/listinfo/pdb-tech
stefan@20c.com (Stefan Pratter) wrote:
put(data=json.dumps(data))
Stefan - THANKS! I owe you a json.dumps(beer) - the conversion step is crucial.. So, in essence, one needs to - use the entire object dict, not just changes - json.dumps() it before throwing it at data= (I had understood the requests object wrongly) Thank you again, this has helped tremendously. - Elmar.
participants (3)
-
Elmar K. Bins -
Mike Simkins -
Stefan Pratter