Unable to update SharePoint List items using shareplum - python

I have a Python script that I've been running for months that uses shareplum to update various columns of a SharePoint List using UpdateListItems(kind = 'Update'). It has suddenly stopped working and I've no idea why. I don't get any error messages but the changes I am trying to make are not showing up. Creating a new item is working fine, it's only when I try to update an existing list item. I use the Office365 version of SharePoint.
The List is relatively large with over 500 list items and over 100 columns. The maximum List ID is 1050.
I tested it on another smaller list and it works OK, so it must be an issue with this particular List.
I'd be really grateful if someone could help. Since I'm not getting any error messages I don't know how to check what could be wrong with it.
from shareplum import Site
from shareplum import Office365
authcookie = Office365('https://XXX.sharepoint.com', username= XXX, password= XXX).GetCookies()
site = Site('https://XXX.sharepoint.com/sites/XXX', authcookie=authcookie)
list_ = site.List('TestList')
my_data = [{'ID': '3', 'Title': 'TestTitle'}]
list_.UpdateListItems(data=my_data, kind='Update')
UPDATE: I printed off the result of the response which says '0x80070057', 'Bad parameter passed to Web Server Extensions. Check the information you entered and try again.' I'm not sure if this helps identify what the issue could be?
I am now able to update my List items using Office365-REST-Python-Client instead of shareplum, but still love to know what the issue with shareplum is.

Idk Python, but PowerShell/CSOM allows you to update the item after you have made the update. I'm assuming Shareplum is a wrapper for CSOM, so you should still have the ability to manually trigger the update.
I don't remember the code of the top of my head, but to manually update it it's something like this (in CSOM):
$listItem = get-pnplistitem -Identity 1 -list "Documents"
$listItem.Fields["Title"] = "New Title"
$listItem.Update()
$listItem.context.executeQuery()

Related

How to get the parent folder name of Message with Exchangelib python

I have an Item object obtained by filtering on an account using exchangelib in python 3.7. It is an email object. I need to find the parent folder name of this item. I specifically need the name field of the folder(This is for tracking where specific emails are moved in a mailbox).
I can see a field parent_folder_id in the item object which returns what I think is a valid folder id. This is also for a production mailbox where account.root.get_folder(folder_id=idObj) times out due to Exchange settings which I cannot change. Pretty much any request which caches fails with a timeout.
account=Account(...)
mailItems=account.inbox.all().filter(subject="foo")
print([i.parent_folder_id.id for i in mailItems])
This prints a list of folder ids. I need the names of these folders. Unclear how to proceed. Any help would be appreciated
Since you're only searching account.inbox and not its subfolders, parent_folder_id will always point to account.inbox.
There's not a very good API yet for looking up folders by e.g. ID. The best solution currently is to use a folder QuerySet:
from exchangelib.folders import SingleFolderQuerySet
f = SingleFolderQuerySet(
account=account,
folder=account.root
).get(id=i.parent_folder_id.id)

transform JSON file to be usable

Long story short, i get the query from spotify api which is JSON that has data about newest albums. How do i get the specific info from that like let's say every band name or every album title. I've tried a lot of ways to get that info that i found on the internet and nothing seems to work for me and after couple of hours im kinda frustrated
JSON data is on jsfiddle
here is the request
endpoint = "https://api.spotify.com/v1/browse/new-releases"
lookup_url = f"{endpoint}"
r = requests.get(lookup_url, headers=headers)
print(r.json())
you can find the
When you make this request like the comments have mentioned you get a dictionary which you can then access the keys and values. For example if you want to get the album_type you could do the following:
print(data["albums"]["items"][0]["album_type"])
Since items contains a list you would need to get the first values 0 and then access the album_type.
Output:
single
Here is a link to the code I used with your json.
I suggest you look into how to deal with json data in python, this is a good place to start.
I copied the data from the jsfiddle link.
Now try the following code:
import ast
pyobj=ast.literal_eval(str_cop_from_src)
later you can try with keys
pyobj["albums"]["items"][0]["album_type"]
pyobj will be a python dictionary will all data.

Understanding Todoist-API

I am trying to use the Todoist-API for Python. I found the official docs on the internet and downloaded the GitHub-Repo. Unfortunately I don't get out how to add a new task.
I do the normal login:
api = todoist.TodoistAPI(XYZ)
api.sync
Then I try to add a new task:
item = api.items.add('Task1')
It tells me I have to give two arguments: name and project_id:
item = api.items.add('Task1', 128501470)
Does anyone know where I could get all my projects IDs? I just want to use the Inbox-Project (default).
I'm not very familiar with this specific API, but considering you're using this api: https://github.com/doist/todoist-python, you can probably do something like:
response = api.sync()
projects = response['projects']
for project in projects:
print(project['name'] + '-' + project['id'])
Basically printing all the names and id's
Just open Todoist in a web browser and look at the address bar, it's right after "project", I beleive you need to truncate the first three or 4 characters though, click through a few projects and you'll see the project id's change.
To add them to the inbox the easiest way is to do the following:
from todoist.api import TodoistAPI
apiToken = 'your token"
todoist: TodoistAPI = TodoistAPI(api_token)
response = todoist.add_item("Item1")
todoist.sync()
todoist.commit()
You will have to refresh either the web page or your app to immediately see the new item

Trying to change a username in Python Google Admin SDK

I'm trying to change a username using the Admin SDK. I'm trying the following code to update this, using a dict object to store the new info, and using patch to update:
userinfo['primaryEmail'] = D['new_user'] + '#' + D['domain']
appsservice.users().patch(userKey = userEmail, body=userinfo)
It doesn't seem to be working, when I look at the admin console. The original username remains unchanged. I'm just wondering if I'm using the correct method. Should I be updating a different variable than primaryEmail or without using the domain affiliation? Seems like I'm just missing something rather obvious.
Thanks,
Tom
Add:
.execute()
To the end of the 2nd line to actually execute the api operation.

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

Categories