I'm trying to download a text file from my sharepoint using the following code.
from shareplum import Site
from shareplum import Office365
from shareplum import folder
authcookie = Office365('https://my.sharepoint.com', username='username', password='password').GetCookies()
site = Site('https://my.sharepoint.com/', authcookie=authcookie)
folder_1 = site.folder('Shared Documents/This folder')
folder_1.download_file('test.txt')
I get the following error when I run the code:
AttributeError: '_Site2007' object has no attribute 'folder'
Any help is appreciated
I am able to reproduce your issue. Please add following parameter in your code:
from shareplum.site import Version
site = Site('https://my.sharepoint.com',version=Version.v365, authcookie=authcookie)
After i specify the version, it works well!
Related
I am trying to create an app to access Etsy api using python3, I am testing my very basic code in idle3, I need to get an oauth token, I have looked at the etsy documentation here but all is described for php.
below is my code in idle3 (I have changed my keys);
>>>payload = { 'api_key' : 'pvhkg9y4e7', 'shared_secret' : 'ib5msimmo', 'scope' : 'transactions_r,listings_w,billing_r,treasury_r'}
>>> url = "https://openapi.etsy.com/v2/oauth/request_token"
>>> r = requests.get(url, params=payload)
>>> print(r.url)
https://openapi.etsy.com/v2/oauth/request_token?api_key=pvhkg9y4e7&scope=transactions_r%2Clistings_w%2Cbilling_r%2Ctreasury_r&shared_secret=ib5msimmo
>>> r.text
>>>'oauth_problem=parameter_absent&oauth_parameters_absent=oauth_consumer_key%26oauth_signature%26oauth_signature_method%26oauth_nonce%26oauth_timestamp
I need help in creating the correct URL I think I need to change my payload wording to oauth_consumer_key, oauth_signature, but I do not understand how to include oauth_signature_method (I am using request.get) or the oauth_timestamp, and I don't know what oauth_nonce is?
I intend to incorporate the whole into a flask app, so I have looked at flask_oauth here but I am not sure if this will give me the timestamp and nonce.
All advice greatly appreciated, I am following the flask tutorial by miguel grinberg, I need one like that for my etsy app! any suggestions
I also tried request_oauthlib but got this;
>>> from requests_oauthlib import OAuth1
>>>Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
from requests_oauthlib import OAuth1
ImportError: No module named 'requests_oauthlib'
Regards
Paul
I wrote to etsy developers, who came back with some php code, I know very little python but no PHP,
So I went back to searching google, and went back to here and used the following code;
import requests
from requests_oauthlib import OAuth1
request_token_url = 'https://openapi.etsy.com/v2/oauth/request_token?scope=transactions_r&listings_w&billing_r&treasury_r'
consumer_key = 'api_key'
consumer_secret = 'secret_key'
oauth = OAuth1(consumer_key, client_secret=consumer_secret)
r = requests.post(url=request_token_url, auth=oauth)
r.content
login_url=https%6%3fthe%26address%26you%2fwant%34goodluck
and it worked!!!!!! I am so happpppy!!!
If you get any other noobs like me perhaps they can be help them with this code.
In terminal I created a virtualenv, I then pip installed requests and request_oauthlib, then in python shell executed the above script.
regards paul
I am trying to locate a search box with id as (search2) from a website. I have been able to successfully login to the website using the below code.
import requests
from tqdm import tqdm
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(executable_path=r'C:\chromedriver_win32\chromedriver.exe', chrome_options=options)
driver.implicitly_wait(30)
tgt = "C:\\mypath"
profile = {"plugins.plugins_list": [{"enabled":False, "name":"Chrome PDF Viewer"}],
"download.default_directory" : tgt}
options.add_experimental_option("prefs",profile)
print(options)
driver.get("http://mylink.com/")
user=driver.find_element_by_id("username")
passw=driver.find_element_by_id("password")
user.send_keys("abc#xyz.com")
passw.send_keys("Pwd")
driver.find_element_by_xpath('/html/body/div[2]/div/div/div[2]/form/div[3]/button').click()
page=driver.find_element_by_id("search2")
print(page)
The code works perfectly till here but the moment I add the below to it I get an error
page.send_keys("abc")
The error that I get is as below.
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
What I am trying to do here is login to the website and search for some items and download the results. I have already tried using the implicitly wait options as mentioned in the code. Any help would be highly appreciated.
Adding the below piece of code did the trick. Had to make the current thread sleep while the program continues to run the next steps.
time.sleep(5)
Thanks everyone.
Hi StackOverflow Community,
Thanks in advance for your help.
I have set up a Python script to make some requests to the Google Sheets API. The code for my script is below:
from googleapiclient import discovery
credentials ='https://www.googleapis.com/auth/spreadsheets' #Should give read/write scope to my spreadsheets
service = discovery.build('sheets', 'v4', credentials=credentials)
spreadsheet_id ='1z2QzPf9Kc02roOwTJUYab4k2dwYu1n-nIbJ5yzWF3YE' #COPY
ranges=['A1:C10']
include_grid_data = False
request = service.spreadsheets().get(spreadsheetId=spreadsheet_id,
ranges=ranges, includeGridData=include_grid_data)
response = request.execute()
The problem is that when I run this I get the following error:
File "C:\Users\evank\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\googleapiclient\_auth.py", line 92, in authorized_http
return credentials.authorize(build_http())
builtins.AttributeError: 'str' object has no attribute 'authorize'
The full code of this file listed in the error is located here: https://github.com/google/google-api-python-client/blob/master/googleapiclient/_auth.py
I'm working on this for an assignment and can't figure out why this error is occurring. Please help!
Thanks,
evank28
I had problems with this.
This link should help: https://medium.com/#rqaiserr/how-to-connect-to-google-sheets-with-python-83d0b96eeea6
Make sure to also read this: https://www.twilio.com/blog/2017/02/an-easy-way-to-read-and-write-to-a-google-spreadsheet-in-python.html
Just note that you need to add this line of code to your project after following the instructions above:
from oauth2client.service_account import ServiceAccountCredentials
and also run this in terminal:
pip install oauth2client
The code will look something like this:
from oauth2client.service_account import ServiceAccountCredentials
import gspread
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)
sheet = client.open_by_url("spreadsheetlink.com")
worksheet = sheet.get_worksheet(0)
Also make sure that you share the client_email with editing access (you will see what I mean after reading the articles).
If you have any questions, feel free to reply to me.
I extremely new to python and practicing Loading a dataset from a url.
When running the following code:
In [1]: myUrl = "http://aima.cs.berkeley.edu/data/iris.csv"
In [2]: urlRequest = urllib.request.Request(myUrl)
I get this error:
File "", line 1, in
urlRequest = urllib.request.Request(myUrl)
AttributeError: 'module' object has no attribute 'request'
1) I tried researching this error and attempted to use import urllib3 again and it imported fine. However when attempting the request I get that error...
2) I attempted to get "help" help("urllib3") in python 3.6.0 and got:
No Python documentation found for 'urllib3'. Use help() to get the
interactive help utility. Use help(str) for help on the str class.
3) I searched Stackoverflow and saw a similar question; tried the suggestions and was not able to move past that line of code...
Am I doing something wrong here?
Thanks in advance for your time
From what I see "request" is not a package, meaning that you can't directly import classes from it.
try :
from urllib.request import Request
myUrl = "http://aima.cs.berkeley.edu/data/iris.csv"
urlRequest = Request(myUrl)
So, as a replacement for mechanize because Visual Studio "needs" python 3.4, and mechanize isn't compatible with 3.4, I found "robobrowser" as a replacement, but I'm having trouble trying to figure out why browser.open returns "AttributeError: 'module' object has no attribute 'open'"
import re
from robobrowser import browser
import time
br = browser
br.open("Website")
br.select_form(name="game-pin-input")
print ("Enter the game pin")
response = br.submit()
time.sleep(3)
Any suggestions, or replacements?
Edit: The Documentation can be found here, and "open" is valid.
https://robobrowser.readthedocs.org/en/latest/api.html#module-robobrowser.browser
I'm guessing browser is a module; according to the docs, you wanted RoboBrowser, and you need to construct an instance before open-ing anything. To roughly match your code:
from robobrowser import RoboBrowser
# Browse to Genius
br = RoboBrowser(history=True) # No idea if history matters
br.open("Website")
I'm guessing robobrowser.browser is some implementation internal module that is importable, but not at all what you wanted.
Update: According to your own docs link, robobrowser.browser is just a module, and RoboBrowser is the class you needed, confirming my earlier statement (RoboBrowser is probably exposed on robobrowser itself for convenience).