Downloading Image with Python Telegram API - python

I followed their brief tutorial on downloading an image but I'm encountering an exception:
telegram.photosize.PhotoSize object at ... is not JSON serializable
the function for catching the images looks like this:
def photo(bot, update):
file_id = update.message.photo[-1]
newFile = bot.getFile(file_id)
newFile.download('test.jpg')
bot.sendMessage(chat_id=update.message.chat_id, text="download succesfull")
photo_handler = MessageHandler(Filters.photo, photo)
dispatcher.add_handler(photo_handler)
The Exception occurs while getting the file.
I have tried all kinds of files however im was not succesful with the download.
At this point I have no idea what I'm doing wrong and can't find any solution on the net.

Related

Pytube AttributeError: 'NoneType' object has no attribute 'span'

Hi I have a problem with AttributeError: 'NoneType' object has no attribute 'span' I read on the StackOverflow a channel with this problem on this I found the potential solution but it still not working here was a advice to change a
this:
152: func_regex = re.compile(r"function\([^)]+\)")
to this
152: func_regex = re.compile(r"function\([^)]?\)")
but it is not working and I do not know how to solute it because A youtube Stil upgrading a platform and this error will be probably in the future too.
So I can Ask is some other method to download a youtube video.
from pytube.__main__ import YouTube
from pytube.streams import Stream
def downloadVideo(link):
video = pytube.YouTube(link)
video.streams.get_highest_resolution().download()
try:
os.rename(video.streams.get_highest_resolution().default_filename, word +".mp4")
except Exception:
print("Expection in renamed file ")
Sorry for the bad indentation but the os.rename ... is too long for write it here
In pytube/cipher.py on line 293, change the line:
name = re.escape(get_throttling_function_name(js))
to
name = "iha"
Answered by czarnoff on the pytube github. If you have any bugs with pytube, I would recommend you check the issues section on the pytube github because bugs get fixed there the fastest.

Attribute Error for Usage of Python Email Import

def ExtractBody(self, msg):
content = ""
if msg.is_multipart():
for payload in msg.get_payload():
content += str(payload.get_payload())
else:
content += str(msg.get_payload())
return content
Hello everyone, with the code above, I was trying to extract the body of a .eml file from a class, but when I used the code above, it gives me the error as shown below.
Why is this so, and how can I fix it?
For extra information, I am getting this email from a web server that makes use of flask.
<class 'AttributeError'>
'bytes' object has no attribute 'read'
EDIT: I have a temporary fix to the problem
I am not sure why, but when I shifted the method from the class to the .py file itself, the code now works.

Trying to make a Watson IBM assistant in Python. How can I fix my code to say the answer within the IDE Pycharm without the audio file. Using VLC

Locked. There are disputes about this question’s content being resolved at this time. It is not currently accepting new answers or interactions.
This is the code grabbed from another Watson based question. I am trying to make a system where I input my speech as a question or command and it says an answer within the IDE here is the link to my previous question My Previous Question but how can I fix the code below.
This is the code...
import vlc
from ibm_watson import TextToSpeechV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator("API Key")
text_to_speech = TextToSpeechV1(
authenticator=authenticator
)
text_to_speech.set_service_url(
'https://api.us-south.text-to-speech.watson.cloud.ibm.com/instances/113cd664-f07b-44fe-a11d-a46cc50caf84')
# define VLC instance
instance = vlc.Instance('--input-repeat=-1', '--fullscreen')
# Define VLC player
player = instance.media_player_new()
# Define VLC media
media = instance.media_new(
text_to_speech.synthesize(
'Hello world',
voice='en-US_AllisonVoice',
accept='audio/wav').get_result().content)
# Set player media
player.set_media(media)
# Play the media
player.play()][1]
After Logging, there was definitely an improvement. I changed the key and URL and only get 2 small code errors...
Traceback (most recent call last):
File "C:/Users/PycharmProjects/IBM Test/iBM tEST.py", line 24, in <module>
accept='audio/wav').get_result().content)
File "C:\Users\PycharmProjects\IBM Test\venv\lib\site-packages\vlc.py", line 1947, in media_new
if ':' in mrl and mrl.index(':') > 1:
TypeError: a bytes-like object is required, not 'str'
The error is telling you that the python runtime can't find the vlc module. You need to run
pip install python-vlc
or
sudo pip install python-vlc
Edits for secondary question
You are going to need to debug your code to work find out what error the service is returning. To do that you are going to have to break up your code.
try:
result = text_to_speech.synthesize(
'Hello world',
voice='en-US_AllisonVoice',
accept='audio/wav').get_result()
print(result)
except Exception as e:
print(e.message)
edits for third question
http 404 is not found implying that you have the wrong url
edits for fourth question
http 403 is forbidden, which implies the combination of url, key and method is invalid. Largely suggesting that you are using the url and key for a completely different service.

Automation process for uploading image to the web site from computer folder in Python

I am trying to upload image from the folder on my PC, and the problem is- I cannot use send_keys as it should be uploaded from the list of images from the folder. Please see attached photo and code:
def picture(self):
path = "/home/nataliya/Desktop/dog.png"
editPhoto = self.driver.find_element_by_xpath('//* [#id="easSettingAvatarUpload"]')
editPhoto.click()
time.sleep(2)
editPhoto.send_keys(path)
editPhoto.submit()
Error I get: AttributeError: 'NoneType' object has no attribute 'send_keys'
I was calling a wrong thing :)
That worked:
path = "/home/nataliya/Desktop/cat.jpg"
editPhoto = self.driver.find_element_by_xpath('//*[#id="easSettingAvatarUpload"]')
time.sleep(2)
editPhoto.send_keys(path)
time.sleep(2)

Google Drive indexableText for a video in Python

I am trying to add indexable text to a video already in drive. From the Drive SDK Docs I used the Patch method.
def add_indexable_text(service, file_id, text_to_index):
try:
file = {'indexableText': {'text': text_to_index}}
updated_file = service.files().patch(
fileId = file_id,
body = file,
fields = 'indexableText').execute()
return updated_file
except errors.HttpError, error:
print 'An error occurred: %s' % error
return None
I'm not seeing any errors in the terminal but when I search in drive for the metadata text there are no results. I've tried waiting for a while but that didn't seem to help/matter. The video says it was updated when I ran the script so there's something. Thanks for any help you can provide.
Update: It seems I can only add indexableText to a video once but not change it afterward.
The code looks fine to me. Try using the "try it" function of the docs, does that work?
https://developers.google.com/drive/v2/reference/files/patch
Maybe the request went through but failed, which causes no HttpError.
What's the return value from a typical call?

Categories