i have this script for downloading the youtube video
from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=kAGacI3JwS4')
#yt.title
#yt.thumbnail_url
#yt.streams.all()
stream = yt.streams.first()
#stream
stream.download('C:\\Users\')
but i wanted this to happened based on a user prompt mode.so it should ask the user to enter the url then from there take it further and download the video,so i did like this
>>> pk=input("Enter the url:")
Enter the url:https://www.youtube.com/watch?v=GhklL_kStto
>>> pk
'https://www.youtube.com/watch?v=GhklL_kStto'
>>> pk.title
<built-in method title of str object at 0x02362770>
>>> pk.stream()
Traceback (most recent call last):
File "<pyshell#44>", line 1, in <module>
>>pk.stream()
AttributeError: 'str' object has no attribute 'stream'
so this is what the error am getting. can someone help me to solve this issue?
appreciate your support!
I hope this answer isn't too late, but the problem is that pk is a string because of this:
pk=input("Enter the url:")
pk is assiged to a string here (aka whatever you input), so there's no way you would have created the relevant Youtube object.
The description you get when you enter pk.title attests to that where it says it's a built in method of a str object. You haven't even made a YouTube object for it to have even a stream method.
You can fix it like this:
url = input("Enter the url:")
pkl = YouTube(url)
pkl.stream()
Hope this helps
Related
`So, this is my code
# Import libraries
import json
import requests
# defining key/request url
key = "https://api.binance.com/api/v3/ticker/price?symbol=USDTKGS"
# requesting data from url
data = requests.get(key)
data = data.json()
print(f"{data['symbol']} price is {data['price']}")
But for some reason I get this error:
Traceback (most recent call last):
File "rate.py", line 11, in <module>
print(f"{data['symbol']} price is {data['price']}")
KeyError: 'symbol'
Probably, this pair doesn't exist, but what to do in such situation?
I need to get the pair by API, but don't see any other ways to do so...
Please, help me!
I tried to use usual pairs like USDT/UAH, EUR/USDT - they work
But USDT/KGS, USDT/KZT doesn't work - they print error, but I need to get it
There is no such pair in Binance API currently (12/10/2022)
First, let me disclaim that I am extremely new to the coding world and work requires me to use Python going forward. My experience is limited to having just completed SANS 573.
I'm trying to obtain the Date and Time from image files in their various formats. Excuse the example, I'm just using this to try and get it working.
This what I currently have:
from pathlib import Path
from PIL import Image
L88 = Path("L88.jpg")
def corvette(L88):
imgobj=Image.open(L88)
info=imgobj._getexif()
return info[36867]
>>> corvette(L88)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in corvette
KeyError: 36867
>>>
I am running the function from the desktop which is where I have the image currently saved.
I don't understand the error messages.
KeyError: 36867 also has me confused too as when I looked up the tag, that is what I found and what worked when I just did my course.
The _getexif() method returns a Python datastructury called a dictionary.
The values in a dictionary are accessed by their key.
In this case, the keys are numbers.
Not all keys are mandatory. You can use the keys() method to see which ones exist. Try:
print(info.keys())
to see which keys exist.
You can also test if a key exists:
if 36867 in info:
return info[36867]
else:
return None
Note that there is a mapping between these numbers and their exif tags names available.
You can use that to create a readable dictionary.
Note that not all JPEG images have EXIF information. In that case, the _getexif() method returns None, so you should take that into account and test for that:
from PIL import Image, ExifTags
def image_info(path):
imgobj = Image.open(path)
info = imgobj._getexif()
if info is None:
return None
rv = {
ExifTags.TAGS[key]: info[key]
for key in info.keys()
}
return rv
i have an active directory running and would like to change an attribute of an user. Im using the python3 ldap3 library and the modify() method.
My code below trows an exception every time i try to modify the user.
from ldap3 import Server, Connection, MODIFY_REPLACE
server = Server('ldaps://domain.local:636', port = 636, use_ssl = True)
try:
conn = Connection(server, user="philipp#domain.local", password="MYPW", auto_bind=True)
print("User found")
except:
print("User not found or connection error")
result = conn.modify('CN=phil stone,OU=Firewall,DC=domain,DC=local',{'rules': [(MODIFY_REPLACE, ['replaced-text'])]})
print(result)
Traceback (most recent call last):
File "/mnt/hgfs/shared/eclipse/osfipa/ldap/ldap_write.py", line 28, in <module>
result = conn.modify('CN=phil stone,OU=Firewall,DC=domain,DC=local',{'rules': [(MODIFY_REPLACE, ['replaced-text'])]})
File "/usr/local/lib/python3.5/dist-packages/ldap3/core/connection.py", line 763, in modify
raise LDAPChangesError(self.last_error)
ldap3.core.exceptions.LDAPChangesError: malformed change
In the AD GUI i have checked the Attribute "distinguishedName" of the User(Object) and its Value is "CN=philipp stone,OU=Firewall,DC=domain,DC=local".
So the DN for the modify function should be correct. And i want to change the "rules" attribute.
Any Ideas what im doing wrong here?
Thx in advance.
https://github.com/cannatag/ldap3/issues/42
There is a simple syntax error. In the above link one can finde the answer.
The simple solution was to change it like the code below.
result = conn.modify('CN=phil stone,OU=Firewall,DC=domain,DC=local',{'rules': (MODIFY_REPLACE, ['replaced-text'])})
Look at the part "MODIFY_REPLACE replaced-text", there is no list([]) around it;)
I am going through the Beautiful Soup page of this book
Python for Secret Agents by Steven Lott Dec 11, 2015 2nd edition
http://imgur.com/EgBnXmm
I ran the code from the page and got this error:
Traceback (most recent call last):
File "C:\Python35\Draft 1.py", line 12, in
timestamp_tag, *forecast_list = strong_list
ValueError: not enough values to unpack (expected at least 1, got 0)
For the life of me I cannot figure out the correct way to fix the code listed here in its entirety:
from bs4 import BeautifulSoup
import urllib.request
query= "http://forecast.weather.gov/shmrn.php?mz=amz117&syn=amz101"
with urllib.request.urlopen(query) as amz117:
document= BeautifulSoup(amz117.read())
content= document.body.find('div', id='content').div
synopsis = content.contents[4]
forecast = content.contents[5]
strong_list = list(forecast.findAll('strong'))
timestamp_tag, *forecast_list = strong_list
for strong in forecast_list:
desc= strong.string.strip()
print( desc, strong.nextSibling.string.strip() )
Thanks a million.
You are experiencing the differences between parsers. And, since you have not provided one explicitly, BeautifulSoup picked one automatically based on internal ranking and what you have installed in the Python environment - I suspect, in your case, it picked up lxml or html5lib. Switch to html.parser:
document = BeautifulSoup(amz117.read(), "html.parser")
I am getting
SearchBackendError at /forum/search/
No fields were found in any search_indexes. Please correct this before attempting to search.
with search_indexes placed in djangobb app root directory:
from haystack.indexes import *
from haystack import site
import djangobb_forum.models as models
class PostIndex(RealTimeSearchIndex):
text = CharField(document=True, use_template=True)
author = CharField(model_attr='user')
created = DateTimeField(model_attr='created')
topic = CharField(model_attr='topic')
category = CharField(model_attr='topic__forum__category__name')
forum = IntegerField(model_attr='topic__forum__pk')
site.register(models.Post, PostIndex)
settings.py
# Haystack settings
HAYSTACK_SITECONF = 'search_sites'
HAYSTACK_SEARCH_ENGINE = 'whoosh'
HAYSTACK_WHOOSH_PATH = os.path.join(PROJECT_ROOT, 'djangobb_index')
also i havae haystack and whoosh in my installed apps.
In python interpreter:
>>> import haystack
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../lib/python2.7/django_haystack-1.2.5-py2.5.egg/haystack/__init__.py", line 26, in <module>
raise ImproperlyConfigured("You must define the HAYSTACK_SITECONF setting before using the search framework.")
django.core.exceptions.ImproperlyConfigured: You must define the HAYSTACK_SITECONF setting before using the search framework.
Has someone has any ideas? Thanks in advance for any help you might have to offer.
Notice that the value shown in the documentation for HAYSTACK_SITECONF is an example only. The real name should be the module where the SearchIndex-derived classes are defined. So, as in your case the module is search_indexes, then you should have HAYSTACK_SITECONF='search_indexes'
Also, about that error that appears at the interpreter, did you get it using python ./manage.py shell? If not, settings.py wasn't loaded at the interpreter.