I just installed caldav 0.5.0 using pip on Windows. I tried to use this code from the documentation:
from datetime import datetime
import caldav
from caldav.elements import dav, cdav
# Caldav url
url = "https://user:pass#hostname/caldav.php/"
client = caldav.DAVClient(url)
But I get this error:
AttributeError: module 'caldav' has no attribute 'DAVClient'
Does someone know what causes this issue?
It is because your file is named calendar.py, which causes some kind of collision somewhere. Renaming your file to something else will do the trick (it did for me).
Related
Is the H2OModelSelectionEstimator deprecated? When I run the code
from h2o.estimators import H2OModelSelectionEstimator
I get the message: ImportError: cannot import name 'H2OModelSelectionEstimator' from 'h2o.estimators'
Try this instead:
from h2o.estimators.model_selection import H2OModelSelectionEstimator
If you can't import it, then you probably don't have the latest version of H2O, so you should download it. ModelSelection was just released in 3.36.0.1.
I have always used R and now trying to switch to Python.
I'm using Pycharm and found this error when running the following code:
import pandas as pd
from bs4 import BeautifulSoup
example1 = BeautifulSoup(train["review"][0],"lxml")
print (example1.get_text())
When I run it I have:
ImportError: cannot import name 'BeautifulSoup'
But I don't have any problem using the console. The rest of the code works fine both with the Run command/terminal and console.
Thank you for your help
Oh,I think you should check your file name or folder name.If there is a name that is already used in bs4 module,you will got ImportError.
Hope this helps.
I am trying to run this app:
https://github.com/bmjr/guhTrends
I have python 2.7.x running the following script at command line. I reckon it was written using python3.x. What is deprecated in the code below?
import urllib
import json
import matplotlib.pyplot as plt
dates = urllib.request.urlopen('http://charts.spotify.com/api/tracks/most_streamed/global/weekly/')
dataDates = json.loads(dates.read().decode())
the error:
Traceback (most recent call last):
File "DataMining.py", line 6, in <module>
dates = urllib.request.urlopen('http://charts.spotify.com/api/tracks/most_streamed/global/weekly/')
AttributeError: 'module' object has no attribute 'request'
That script won't work under python2 as urllib of python2 has no request module.
Use urllib2.urlopen instead of urllib.request if you want start running that script under python2 .
To get python script work on bith (python2 and python3) use six module which is Python 2 and 3 Compatibility Library.
from six.moves import urllib
import json
import matplotlib.pyplot as plt
dates = urllib.request.urlopen('http://charts.spotify.com/api/tracks/most_streamed/global/weekly/')
dataDates = json.loads(dates.read().decode())
You're requesting a resource that is not currently available (I'm seeing a 504). Since this could potentially happen any time you request a remote service, always check the status code on the response; it's not that your code is necessarily wrong, in this case it's that you're assuming the response is valid JSON without checking whether the request was successful.
Check the urllib documentation to see how to do this (or, preferably, follow the recommendation at the top of that page and use the requests package instead).
Accocrding this manual I shoud use thise pice of code:
from azure.storage.blob import ContentSettings
block_blob_service.create_block_blob_from_path(
'mycontainer',
'myblockblob',
'sunset.png',
content_settings=ContentSettings(content_type='image/png')
)
But got this error:
AttributeError: 'BlockBlobService' object has no attribute 'create_block_blob_from_path'
Tried from git, as well as from pip
pip install azure-storage
I believe the tutorial is out of date, compared with the latest Python SDK. I don't think there's a create_block_blob_from_path anymore - I looked at the sdk code (here). There are separate imports for block blobs and page blobs, with the method being create_blob_from_path.
So with a simple correction:
from azure.storage.blob import BlockBlobService
from azure.storage.file import ContentSettings
blob_service = BlockBlobService(account_name="<storagename>",account_key="<storagekey>")
content_settings = ContentSettings(content_type = "image/png")
blob_service.create_blob_from_path("mycontainer","myblockblob","sunset.png",content_settings)
I am getting the following error:
Cannot Import Name DtdProcessing
On this line:
from System.Xml import (DtdProcessing, ValidationType, XmlNodeType, XmlReader, XmlReaderSettings)
What could be causing this? Is there a possibility that I don't have the right version of .net installed?