I'm trying to debug a script that's trying to talk to RT (Request Tracker) and I'm getting the following output:
RT/3.6.6 409 Syntax Error
# Syntax Error
>>ARRAY(0x2b3495f37750)
I have no idea what this error means in the context of RT given the astounding lack of detail making it difficult to debug. Here's the associated code for a little context, it's a script trying to create a ticket.
import requests
def combDicts(dicts):
out = {}
for d in dicts:
out.update(d)
return out
operPath = 'ticket/new'
credentials = {'user': 'myuser', 'pass': 'mypassword'}
content = {
'content': {
'id': 'ticket/new',
'Subject': 'Python Script Test',
'Queue': 'General - unassigned',
}
}
r = requests.post('https://rt.hdms.com/REST/1.0/' + operPath, params=combDicts((credentials, content)), verify = False)
print r.text
If I comment out all but the Queue line of the content dict the error changes to:
RT/3.6.6 409 Syntax Error
# Syntax Error
>> Queue
The crux of my question is this: Does anyone know what this error means or know where I can find documentation on what all the RT errors are and what could cause them?
You'll find much more information in the logs on the RT server itself, especially if you up the log level to debug. You might have better luck using one of the python libraries available for calling RT. However, the version of RT you're running is fairly old, released in Jan. 2008. You may have trouble using current libraries with an old version of RT.
Related
I've recently started working with the Facebook Marketing API, using the facebook_business SDK for Python (running v3.9 on Ubuntu 20.04). I think I've mostly wrapped my head around how it works, however, I'm still kind of at a loss as to how I can handle the arbitrary way in which the API is rate-limited.
Specifically, what I'm attempting to do is to retrieve all Ad Sets from all the campaigns that have ever run on my ad account, regardless of whether their effective_status is ACTIVE, PAUSED, DELETED or ARCHIVED.
Hence, I pulled all the campaigns for my ad account. These are stored in a dict, whereby the key indicates the effective_status, like so, called output:
{'ACTIVE': ['******************',
'******************',
'******************'],
'PAUSED': ['******************',
'******************',
'******************'}
Then, I'm trying to pull the Ad Set ids, like so:
import pandas as pd
import json
import re
import time
from random import *
from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount # account-level info
from facebook_business.adobjects.campaign import Campaign # campaign-level info
from facebook_business.adobjects.adset import AdSet # ad-set level info
from facebook_business.adobjects.ad import Ad # ad-level info
# auth init
app_id = open(APP_ID_PATH, 'r').read().splitlines()[0]
app_secret = open(APP_SECRET_PATH, 'r').read().splitlines()[0]
token = open(APP_ACCESS_TOKEN, 'r').read().splitlines()[0]
# init the connection
FacebookAdsApi.init(app_id, app_secret, token)
campaign_types = list(output.keys())
ad_sets = {}
for status in campaign_types:
ad_sets_for_status = []
for campaign_id in output[status]:
# sleep and wait for a random time
sleepy_time = uniform(1, 3)
time.sleep(sleepy_time)
# pull the ad_sets for this particular campaign
campaign_ad_sets = Campaign(campaign_id).get_ad_sets()
for entry in campaign_ad_sets:
ad_sets_for_status.append(entry['id'])
ad_sets[status] = ad_sets_for_status
Now, this crashes at different times whenever I run it, with the following error:
FacebookRequestError:
Message: Call was not successful
Method: GET
Path: https://graph.facebook.com/v11.0/23846914220310083/adsets
Params: {'summary': 'true'}
Status: 400
Response:
{
"error": {
"message": "(#17) User request limit reached",
"type": "OAuthException",
"is_transient": true,
"code": 17,
"error_subcode": 2446079,
"fbtrace_id": "***************"
}
}
I can't reproduce the time at which it crashes, however, it certainly doesn't take ~600 calls (see here: https://stackoverflow.com/a/29690316/5080858), and as you can see, I'm sleeping ahead of every API call. You might suggest that I should just call the get_ad_sets method on the AdAccount endpoint, however, this pulls fewer ad sets than the above code does, even before it crashes. For my use-case, it's important to pull ads that are long over as well as ads that are ongoing, hence it's important that I get as much data as possible.
I'm kind of annoyed with this -- seeing as we are paying for these ads to run, you'd think FB would make it as easy as possible to retrieve info on them via API, and not introduce API rate limits similar to those for valuable data one doesn't necessarily own.
Anyway, I'd appreciate any kind of advice or insights - perhaps there's also a much better way of doing this that I haven't considered.
Many thanks in advance!
The error with 'code': 17 means that you reach the limit of call and in order to get more nodes you have to wait.
Firstly I would handle the error in this way:
from facebook_business.exceptions import FacebookRequestError
...
for status in campaign_types:
ad_sets_for_status = []
for campaign_id in output[status]:
# keep trying until the request is ok
while True:
try:
campaign_ad_sets = Campaign(campaign_id).get_ad_sets()
break
except FacebookRequestError as error:
if error.api_error_code() in [17, 80000]:
time.sleep(sleepy_time) # sleep for a period of time
for entry in campaign_ad_sets:
ad_sets_for_status.append(entry['id'])
ad_sets[status] = ad_sets_for_status
I'd like to suggest you moreover to fetch the list of nodes from the account (by using the 'level': node param in params) and by using the batch calls: I can assure you that this will help you a lot and it will decrease the program run time.
I hope I was helpful.
I am running the following:
import geopy
geolocator = geopy.geocoders.OpenMapQuest(api_key='my_key_here')
location1 = geolocator.geocode('Madrid')
where my_key_here is my consumer key for mapquest, and I get the following error:
GeocoderInsufficientPrivileges: HTTP Error 403: Forbidden
Not sure what I am doing wrong.
Thanks!
I've also tried the same with the same result. After checking the Library, I found out, that the error is referring to the line, where the request ist build and it seems, that the API Key is not transmitted. If you add no key in the init statement, the api_key='' so I tried to change the line 66 in my own Library of the file: https://github.com/geopy/geopy/blob/master/geopy/geocoders/openmapquest.py to my key.
Still no success! The key itself works, I've tested it with calling the URL that is also called in the Library:
http://open.mapquestapi.com/nominatim/v1/search.php?key="MY_KEY"&format=json&json_callback=renderBasicSearchNarrative&q=westminster+abbey
no idea why this isn't working…
Cheers.kg
I made slight progress with fixing this one. I was able to get the query written correctly, but its the json parsing that kind of have me stumped. Maybe someone knows. I know the url is being sent correctly (I checked it in the browser and it returned a json object). Maybe someone knows how to parse the returned json object to get it to finally work.
Anyways, I had to go in the openmapquest.py source code, and starting from line 66, I made the following modifications:
self.api_key = api_key
self.api = "http://www.mapquestapi.com/geocoding/v1/address?"
def geocode(self, query, exactly_one=True, timeout=None): # pylint: disable=W0221
"""
Geocode a location query.
:param string query: The address or query you wish to geocode.
:param bool exactly_one: Return one result or a list of results, if
available.
:param int timeout: Time, in seconds, to wait for the geocoding service
to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
exception. Set this only if you wish to override, on this call
only, the value set during the geocoder's initialization.
.. versionadded:: 0.97
"""
params = {
'key': self.api_key,
'location': self.format_string % query
}
if exactly_one:
params['maxResults'] = 1
url = "&".join((self.api, urlencode(params)))
print url # Print the URL just to make sure it's produced correctly
Now the task remains to get the _parse_json function working.
So my issue is with the Python Library for the JIRA API. We are using JIRA as a asset management database (Yes I know its normal used by dev's and we use it for that as well but this was a case were it worked well) to keep track of are server configs (Memory, CPU, Location on the Rack ..etc..)
Using this function I am having it create a Issue under a Project and pull the information for the fields from another API.
(note that I cant give clues as to who I work for so the code is edited - however it all works expect when i add one line)
def create_compute_node_in_jira(self, compute_node_name ,user_name, password, info_dic):
help_obj = helper()
jira = JIRA("https://",basic_auth=(user_name,password))
#Uses a dic to create the fields / info for the Issue
issue_dict = {
'project': {'key': <project>},
'summary': compute_node_name,
'issuetype': {'name': 'Server Hardware'},
'customfield_10500': str(info_dic["Hostname"]),
'customfield_11007': {'value': str("2U")},
'customfield_11006': str(info_dic["Aggr0-IP"]),
'customfield_10510': {'value': str(7)},
'customfield_10501': str(info_dic["Serial-Number"])
'customfield_10502': {'value': str(<server>)},
'customfield_10503': str(help_obj.data_parser_sm(info_dic["Hostname"])),
'customfield_10509': {'value': str("<OS>")},
'customfield_10504': {'value': str("<mem>")},
'customfield_10505': str(help_obj.data_parser_cpu(info_dic["CpuType"])),
'customfield_10507': {'value': str(info_dic["Cpu-Core"])},
'customfield_10508': {'value': str(<OS Version>)},
'customfield_11008': {'value': str("CMH")}
}
jira.create_issue(fields=issue_dict)
return "[*]Created ticket" # Should exit script after this is returned
The line - 'customfield_11008': {'value': str("CMH")} - causes the function to return the following expection:
jira.utils.JIRAError: JiraError HTTP 400
text: Option id 'null' is not valid
url: https:///rest/api/2/issue
however when i omit that line it runs with out a problem. I tried CMH lower case - capital ..etc.. and it still breaks the scripts. I even went through the web gui and copied the "CMH" entry in another ticket and it stilled caused a problem. Has anybody seen this before / have any guesses as to why it is breaking ?
So after a while of playing around with JIRA I found out it was my own mistake. It seems this error is caused when you post to a field using the API a "value" that it does not understand. A example was I was using the wrong custom field and the JIRA Field that I was posting to was not setup to take the value I was using.
You will see this error when the field's value is expected to match an option list, and you are trying to send a value which is not on this list.
I'm trying to post to a Facebook Page I manage with the Python facebook-sdk but I can't figure out how to do it. I can post to my Facebook Wall like so:
graph.put_object("me", "feed", message='My message goes here')
I can get the pages I manage and the access tokens like so:
fbpages = graph.request('me/accounts')
But I can't find any resources to indicate how to actually then use the access token to post to the page. I imagine it would be something like this:
graph.put_object("me", "page id", "access token", message='My message goes here')
How would I actually go about doing this with the Python facebook-sdk?
I'm using 'pythonforfacebook/facebook-sdk'.
Thank's to WizKid for pointing me in the right direction. For anyone else with this problem it is solved like so:
graph = facebook.GraphAPI(page_access_token)
graph.put_object("page id", "feed", message='My message goes here')
With the new API(v2.8), you can use the following code:
import facebook
def main():
graph = facebook.GraphAPI(access_token='your_user_access_token', version='2.8')
#if version 2.8 show error use 2.6
attachment = {
'name': 'Link name'
'link': 'https://www.example.com/',
'caption': 'Check out this example',
'description': 'This is a longer description of the attachment',
'picture': 'https://www.example.com/thumbnail.jpg'
}
graph.put_wall_post(message='Check this out...', attachment=attachment, profile_id='your_page_id')
if __name__ == "__main__":
main()
You can change the attachment as your need. I think this will be helpful if someone needs to use the new API. You need to install facebook sdk first.
pip install facebook-sdk
I'm trying to access my google talk contacts' custom status messages with xmpppy. I'm made it this far:
import xmpp
import sys
userID = 'myname#gmail.com'
password = 'mypassword'
ressource = 'Script'
jid = xmpp.protocol.JID(userID)
jabber = xmpp.Client(jid.getDomain(), debug=[])
connection = jabber.connect(('talk.google.com',5222))
auth = jabber.auth(jid.getNode(), password, ressource)
jabber.sendInitPresence(requestRoster=1)
myroster = jabber.getRoster()
the roster object myroster now contains my contacts, but the custom status message is not included.
myroster.getStatus('oneofmyfriends#gmail.com')
returns None
looking at the 'raw roster', I can see that the resources dictionary is empty
u'oneofmyfriends#googlemail.com': {'ask': None, 'resources': {}, 'name': u'Some Name', 'groups': [], 'subscription': u'both'}
The weird thing is that I have gotten this to work today, but I the code might have been slightly different, but I can't figure out what exactly I did differently...
Any help would be greatly appreciated!
Cheers,
Martin
Here's one thing I've found, which was not clear to me when I first started working with xmpp. Friending is two-way.
Using presence stanzas
(a) You can "subscribe" to your friend, and your friend can return "subscribed".
(b) Your friend can "subscribe" to you, and you can return "subscribed".
Your friend will be in your roster if either (a) or (b) has happened.
You will be in your friends roster if either (a) or (b) has happened.
However...
You will not see their status unless you "subscribe" to your friend - (a) must happen
They will not see your status unless they "subscribe" to you - (b) must happen.
Most XMPP clients (pidgin, trillian, etc) will automatically make you send "subscribe" back to your friend when you send them "subscribed" (after they've sent you "subscribe"). XMPPPY does not do this out of the box. You must code it to do this.
This could explain why you weren't seeing status. Or if this doesn't cover your situation, it might be informative to someone else.
It's a timing issue. Add a handler with:
jabber.RegisterHandler('presence', myPresenceHandler)
def myPresenceHandler(self, con, event):
fromjid = event.getFrom().getStripped()
status = myroster.getStatus(fromjid)
BEFORE connecting. Then make sure to call jabber.Process() in a loop. The issue is that with your code, you'll sometimes receive presence stanzas before you look at the roster object, and sometimes after.