I am using python for making a post request on tumblr /posts endpoint but getting an error response.
This is the code. Tumblr api use oauth1 authentication.
import requests
from requests_oauthlib import OAuth1
consumer_key = "0000000000000000000000000000000000000"
consumer_secret = "0000000000000000000000000000000000000"
token = "0000000000000000000000000000000000000"
token_secret = "0000000000000000000000000000000000000"
oauth = OAuth1(
consumer_key,
client_secret=consumer_secret,
resource_owner_key=token,
resource_owner_secret=token_secret,
signature_method='HMAC-SHA1'
)
url = 'https://api.tumblr.com/v2/blog/aisamarsha-blog.tumblr.com/posts'
params = {
'type': 'photo',
'state': 'published',
'tags': 'tag1, tag2, tag3',
'content': [
{
'type': 'image',
'url': 'http://69.media.tumblr.com/b06fe71cc4ab47e93749df060ff54a90/tumblr_nshp8oVOnV1rg0s9xo1_250.jpg',
'caption': 'This is the caption for image1'
},
{
'type': 'image',
'url': 'http://69.media.tumblr.com/b06fe71cc4ab47e93749df060ff54a90/tumblr_nshp8oVOnV1rg0s9xo1_250.jpg',
'caption': 'This is the caption for image2'
},
{
'type': 'image',
'url': 'http://69.media.tumblr.com/b06fe71cc4ab47e93749df060ff54a90/tumblr_nshp8oVOnV1rg0s9xo1_1280.jpg',
'caption': 'This is the caption for image3'
}
]
}
response = requests.post(url, auth=oauth, json=params)
print(response.json())
I want to post blog with multple images, tags and caption on tumblr.
Related
hello so i am trying to print only the [code] here but i couldn't
import requests
token = 'token'
id = "35633560231"
headers = {
'Authorization': 'Bearer ' + token,
'Accept': 'application/json',
}
response = requests.get('https://5sim.net/v1/user/check/' + id, headers=headers)
datas = response.json()
smss = datas['sms']
print(smss)
sms print : [{'created_at': '2022-09-09T14:25:01.486075Z', 'date': '2022-09-09T14:25:01.481586Z', 'sender': 'Amazon', 'text': "625172 is your Amazon OTP. Don't share it with anyone.", 'code': '625172'}]
i want to get the code value only i tried smss = smss['code'] but it didn't work
data['sms'] is a list and you have the json object at index 0.
This should work:
sms=[{'created_at': '2022-09-09T14:25:01.486075Z', 'date': '2022-09-09T14:25:01.481586Z', 'sender': 'Amazon', 'text': "625172 is your Amazon OTP. Don't share it with anyone.", 'code': '625172'}]
print(f"Code: {sms[0]['code']}")
output:
Code: 625172
I'm trying to send a POST and I get this error:
{"data":null,"error":{"status":400,"name":"ValidationError","message":"Missing "data" payload in the request body","details":{}}}
In [ ]:
This is my code:
import requests
import json
myToken = '256e8f598edc0990b39dbfe8c4acf39ec83ee3a1a8f212a7656b3892585755c52857503a356ed003fa6b1f5f4b89fc34b0aa64000bb1bf5bba75257a0128365c75aa96a8cb4ed7a32e7fc7b5ec899ae6d2633a7004ef7f991b8ca6e6bdac4a3a75954425f95cc1a209e09272b5582f58690759f81aecb506070c3c19b3cdac2f'
myUrl = 'http://localhost:1337/api/countries'
head = { 'Authorization': 'Bearer {}'.format(myToken), 'Content-Type': 'application/json'}
session = requests.Session()
session.headers.update(head)
Get request & response (working well):
response = session.get(myUrl)
print (response.text)
{
"data":[
{
"id":1,
"attributes":{
"name":"United States",
"createdAt":"2022-04-09T04:15:13.925Z",
"updatedAt":"2022-04-09T04:15:15.226Z",
"publishedAt":"2022-04-09T04:15:15.220Z"
}
}
],
"meta":{
"pagination":{
"page":1,
"pageSize":25,
"pageCount":1,
"total":1
}
}
}
Post request & response:
data = json.dumps(['data', {'name': 'United States'}])
response = session.post(myUrl, data = data)
print (response.text)
{
"data":null,
"error":{
"status":400,
"name":"ValidationError",
"message":"Missing \"data\" payload in the request body",
"details":{
}
}
}
Thanks in advance
I did the solution for that,
First of all: I changed the "data" to "json"
data = {'data': {'name': 'United states'}}
request = session.post(myUrl, json = data)
print (request.text)
Im using get request to get data from a site.
captured reqeuest details :
Query String Parameters
s: vrnf8
following is my code . But i get 404 not found status code.
import requests
url = "https://www.fleetmon.com/search/?s=vrnf8"
pload = {"s":"vrnf8"}
resp = requests.get(url, params=pload)
print(resp.text)
print(resp.status_code)
please help me with this !
request capture file : https://filebin.net/ilx668e5yrdmbu7p
response must be this :
[[{"lastreport_class": "position-age-live", "course": 213, "callsign": "VRNF8", "lastreport_verbose": "2020-07-17 12:28 UTC", "speed": 15.6, "destination": "SGSIN PEBGA", "vessel_url": "/vessels/seaspan-amazon_9630391_8896228/", "imo": "9630391", "location": "South Kuroshio, JP", "latitude": 28.732660, "vesselid": "8896228", "mmsi": "477390400", "lastreport_timestamp": 1594985298, "lastreport_short": "21 min", "name_clean": "SEASPAN AMAZON", "vessel_type": "Container ship", "master_image_id": 2278121, "flag_id": "HK", "icon": "cargo", "is_moving": true, "name": "SEASPAN AMAZON", "longitude": 28.732660, "length": "337", "flag_name": "Hong Kong SAR of China"}], 1, [], 0]
Try this code below:
import requests
url = "https://www.fleetmon.com/search/?s=vrnf8"
headers = {
'X-Requested-With': 'XMLHttpRequest'
}
response = requests.get(url, headers=headers)
print(response.json())
Result:
[[{'lastreport_class': 'position-age-live', 'course': 212, 'callsign': 'VRNF8', 'lastreport_verbose': '2020-07-17 13:22 UTC', 'speed': 15.9, 'destination': 'SGSIN PEBGA', 'vessel_url': '/vessels/seaspan-amazon_9630391_8896228/', 'imo': '9630391', 'location': 'South Kuroshio, JP', 'latitude': 28.540143, 'vesselid': '8896228', 'mmsi': '477390400', 'lastreport_timestamp': 1594988550, 'lastreport_short': '1 min', 'name_clean': 'SEASPAN AMAZON', 'vessel_type': 'Container ship', 'master_image_id': 2278121, 'flag_id': 'HK', 'icon': 'cargo', 'is_moving': True, 'name': 'SEASPAN AMAZON', 'longitude': 28.540143, 'length': '337', 'flag_name': 'Hong Kong SAR of China'}], 1, [], 0]
import requests
url = "https://www.fleetmon.com/search/?s=vrnf8"
pload = {"s":"vrnf8"}
resp = requests.get(url, params=pload)
print(resp.text)
print(resp.status_code)
NOTE: The url you have typed doesn't exist
Correct Code
import requests
url = "https://www.fleetmon.com/search/"
pload = {"s":"vrnf8"}
resp = requests.get(url, params=pload)
print(resp.text)
print(resp.status_code)
But Now also you will get an error
Explanation
let's understand what's happening in your code
import requests
url = "https://www.fleetmon.com/search/?s=vrnf8"
pload = {"s":"vrnf8"}
resp = requests.get(url, params=pload)
'''
resp is equivalent to request.get("https://www.fleetmon.com/search/?s=vrnf8/?s=vrnf8")
when we make get request to url, it appends /?query=value to it's requested url
and this url doesn't exist so you will get 404
'''
print(resp.text)
print(resp.status_code)
code that I sent
```python
import requests
url = "https://www.fleetmon.com/search"
pload = {"s":"vrnf8"}
resp = requests.get(url, params=pload)
'''
resp is equivalent to request.get("https://www.fleetmon.com/search/?s=vrnf8")
when we make get request to url, it again appends /?query=value to it's requested url
and even this url also doesn't exist so you will again get 404
'''
print(resp.text)
print(resp.status_code)
NOTE: You can check weather a url exist or not by typing it in google search bar
I am getting null response while my code is successfully working. I am not able to get response from dialogAction, i am
import json
import requests
def getdata(intent_name, fulfillment_state, message):
response = {
'dialogAction': {
'type': 'Close',
'intentName': intent_name,
'fulfillmentState': fulfillment_state,
'message': message
}
}
return response
def lambda_handler(event,context):
payload = {'userId':4,'type':'PARENT'}
r = requests.post("http://ec2-54-226-57-153.compute-1.amazonaws.com:8080/Tracking/rest/api", data=json.dumps(payload), headers = {'Content-Type': 'application/json','Accept': 'application/json'})
print(r.content)
getdata(
'currentIntent',
'Fulfilled',
{
'contentType': 'PlainText',
'content': 'message'
}
)
From what I understand, your code should be:
import json
import requests
def getdata(message):
return {
'dialogAction':{
'type':'Close',
'fulfillmentState':'Fulfilled',
'message':{
'contentType':'PlainText',
'content':message
}
}
}
def lambda_handler(event, context):
payload = {'userId':4,'type':'PARENT'}
r = requests.post("http://ec2-54-226-57-153.compute-1.amazonaws.com:8080/Tracking/rest/api", data=json.dumps(payload), headers = {'Content-Type': 'application/json','Accept': 'application/json'})
print(r.content)
return getdata(r.content)
Let us know if you are getting any error.
I am having trouble sending a topic downstream message using Firebase. Everything works fine when I send to single or multiples users using tokens, my code looks like this
notif = {
'to': 'TOKEN',
'data': {'msg': 'whatever'},
}
opener = urllib2.build_opener()
data = json.dumps(notif)
req = urllib2.Request(
FCM_URL,
data=data,
headers={
'Content-Type': 'application/json',
'Authorization': 'key=' + API_KEY,
}
)
response = opener.open(req)
However if I replace the recipients using a topic, more precisely the code becomes
notif = {
'to': '/topic/MY_TOPIC',
'data': {'msg': 'whatever'},
}
opener = urllib2.build_opener()
data = json.dumps(notif)
req = urllib2.Request(
FCM_URL,
data=data,
headers={
'Content-Type': 'application/json',
'Authorization': 'key=' + API_KEY,
}
)
response = opener.open(req)
{"multicast_id":id,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
Is there something I am missing? I should outline that sending topic messages from the firebase console works fine.
Any help more than welcome,
Best & thanks!
Alex
Ah so silly...
I was missing s in topics, the correct form is hence
notif = {
'to': '/topics/MY_TOPIC',
'data': {'msg': 'whatever'},
}
Hope it helps someone anyway!
Best,
A