SalesforceObject.search/get not working together? Python / Simple-salesforce - python

Heres what I'm trying to do:
First of all, I want every entry in Account. After that, I want to use get on them to get the whole thing. However, I get an error message. I do the following:
accIdArr = sf.search("FIND {Account}")
print accIdArr
for i in accIdArr:
print i["Id"]
accDataArr = sf.Account.get(i["Id"])
print accDataArr
However, I get this error message:
simple_salesforce.api.SalesforceResourceNotFound: Resource Account Not Found. Response content: [{u'errorCode': u'NOT_FOUND', u'message': u'The requested resource does not exist'}]
I then tried to use sf.Account.get('CopyAndPastedId') with the Id that got printed before I get the error, eg i["Id"].
Well, that doesnt work either and gives the same error. So I thought about Account not existing, however sf.Account.metadata() works fine and gives the expected data.
What am I doing wrong?

Is there a reason to use SOSL rather than SOQL?
Since you are only requesting the Account Objects, a simple SOQL search will get you what you want. Try the following:
accDataDict = sf.query('SELECT ID, Name, <all other fields you want> FROM Account')
The return will be an ordered dictionary of all the Account Objects with the field/values you requested in your query.

Related

Not all arguments converted during string formatting (Flask, ImageMagick and SQLAlchemy_ImageAttach)

I can't really make any sense of this error. When I try to commit a change to user.picture, it sends the error written in the title. I haven't been able to find any other example of this error occurring in anything related to this.
Here's the error:
not all arguments converted during string formatting on line 429
Line 429 reads like so:
db.session.commit()
Here's my store:
store = FileSystemStore(
path='bin/static/img',
base_url='/'
)
If I use a store like this instead, I get the same error:
store = HttpExposedFileSystemStore(
path='bin/static/img/',
prefix='static/img/'
)
Here's an example of me attempting to commit a given picture
with store_context(main.AppClass.store):
current_user.picture.from_file(_profile_picture)
db.session.commit()
Here's an example of me trying to do the same with binary instead
with store_context(main.AppClass.store):
byte_str = base64.b64encode(_profile_picture.read())
decoded_byte_str = base64.b64decode(byte_str)
current_user.picture.from_blob(decoded_byte_str)
db.session.commit()
They both give me the same error, which leads me to believe there may be something wrong with my Store, but I can't really begin to comprehend how.
However, if I do something like this instead as a test to see if it works at all:
with store_context(main.AppClass.store):
current_user.set_name("asd")
db.session.commit()
It commits with no issue. I'm sort of at a loss here, any help is appreciated.

How to query specific information for an issue?

I'm trying to use JIRA python api to receive the list of tickets that have been raised in the last 30 days but whenever i run
Issue = main.jira.issue("PLAT-38592")
i = main.jira.issue(issue, "Summary")
print(i)
All that gets returned is
PLAT-38592
Then i try to poke at the issue
Issue = main.jira.issue("PLAT-38592")
print (Issue)
And all that gets returned is
PLAT-38592
I need to be able receive information from this ticket but it only returns a string
Issues are objects. You can access their content by accessing fields.
If you for example want to access the summary, you can use (according to the docs):
issue = jira.issue('PLAT-38592', fields='summary')
summary = issue.fields.summary
print(summary)

How to use dynamic variable in python mongodb script

I want to update records in the collection books.
I want to create new field whose name and value are the values from variables.
for book in db.books.find():
title = book['title']
author, value = getAuthor(title)
db.dataset.update({"_id": book['_id']}, {"$set": {author: value}})
When I did this I got the error: WriteError: The update path contains an empty field name. It is not allowed which is not true because both variables have values. I googled and resolved this issue by enclosing author into []. So the code looks like this:
for book in db.books.find():
title = book['title']
author, value = getAuthor(title)
db.dataset.update({"_id": book['_id']}, {"$set": {[author]: value}})
But now I am getting this error which I am not able to resolve:
TypeError: unhashable type: 'list'
Does anyone have encountered such problem? How can I resolve it?
It sounds like getAuthor() is returning back nothing for it's first value, so author is getting set to nothing. From what I can see you did not resolve the error, you just changed it to a different error. By making it say [author] (though it's been a while since I've been in Python) I believe you're just trying to set the key to be an empty list, or a list with an empty string as the only value, depending on what author is.
If I were you, I would print out what author is, or do some debugging and figure out what you're getting back from getAuthor(). Since I can't see that code, nor the data in your database, I'm not sure how to help further without more information.

tweepy get_user does not work with a list of user_ids

I am using tweepy library to pull informations about Twitter users. What I want is, given a list of Twitter ids, get the number of followers of each user that relates to the ids. The function looks like this.
infos = api.get_user(user_id=xxx)
return infos.followers_count
In the Twitter documentation, it says I can input a list of up to 100 user ids to get_user. Thing is, whatever I pass to that function other than a single id, I get the error
[{'message': 'Sorry, that page does not exist', 'code': 34}]
For example if I write:
infos = api.get_user(user_id=[user1,user2,user3])
I get the error. But if I write
infos = api.get_user(user_id=user1)
It works perfectly well. Did you encounter this problem before? Is the problem in Tweepy library? Should I use another library?
Thanks for your support
You need to use the function lookup_users for this, and the parameter is user_ids:
infos = api.lookup_users(user_ids=[user1,user2,user3])
https://github.com/tweepy/tweepy/blob/master/tweepy/api.py#L154

LinkedIn REST API does not return end-date with python

I'm working on Linkedin REST API. I cannot get postions' end-date.
connectionsdic = application.get_connections(selectors=['id',
'positions','specialties','first-name','last-name',
'headline','public-profile-url','site-standard-profile-request'],
params=`{'start':130, 'count':100})
I can get anything else.
Edit: I changed my code to be most straight, but still same result...
Try just specifying positions without the :['end-date'] part, in the same you specify educations.
Also note that end date will not be returned if the position is current.

Categories