admin管理员组文章数量:1026912
I have some problems with server.
import time
import instaloader
import requests
from io import BytesIO
def instagram_downloander(url, content_type):
print(f"Content Type: {content_type}")
try:
ig = instaloader.Instaloader()
shortcode = url.split('/')[-2]
post = instaloader.Post.from_shortcode(ig.context, shortcode)
for _ in range(3):
try:
post = instaloader.Post.from_shortcode(ig.context, shortcode)
if post.is_video:
video_url = post.video_url
response = requests.get(video_url)
if response.status_code == 200:
return BytesIO(response.content), 'video'
else:
image_url = post.url
response = requests.get(image_url)
if response.status_code == 200:
return BytesIO(response.content), 'image'
except instaloader.exceptions.TooManyRequestsException:
print("Rate limit reached. Retrying after delay...")
time.sleep(600)
except Exception as e:
print(f"Retry failed: {e}")
print("Unable to download the post. Please try later.")
return None, None
except instaloader.exceptions.BadResponseException as e:
print(f"An error occurred while fetching post metadata: {e}")
return None, None
except Exception as e:
print(f"Unexpected error: {e}")
time.sleep(10)
return instagram_downloander(url, content_type)
This is my insta.py file and
elif user_state.get(user_id) == 'instagram_post':
url = update.message.text
content_type = 'post'
await update.message.reply_text("Please wait 1 minute for loading...")
media, media_type = instagram_downloander(url, content_type)
if media and media_type:
if media_type == 'video':
await update.message.reply_video(video=media, filename='instagram_video.mp4')
elif media_type == 'image':
await update.message.reply_photo(photo=media, filename='instagram_image.jpg')
else:
await update.message.reply_text("Unsupported media type.")
# Credit.deduct_credits(user_id, 1)
await update.message.reply_text(f"I have some problems with server.
import time
import instaloader
import requests
from io import BytesIO
def instagram_downloander(url, content_type):
print(f"Content Type: {content_type}")
try:
ig = instaloader.Instaloader()
shortcode = url.split('/')[-2]
post = instaloader.Post.from_shortcode(ig.context, shortcode)
for _ in range(3):
try:
post = instaloader.Post.from_shortcode(ig.context, shortcode)
if post.is_video:
video_url = post.video_url
response = requests.get(video_url)
if response.status_code == 200:
return BytesIO(response.content), 'video'
else:
image_url = post.url
response = requests.get(image_url)
if response.status_code == 200:
return BytesIO(response.content), 'image'
except instaloader.exceptions.TooManyRequestsException:
print("Rate limit reached. Retrying after delay...")
time.sleep(600)
except Exception as e:
print(f"Retry failed: {e}")
print("Unable to download the post. Please try later.")
return None, None
except instaloader.exceptions.BadResponseException as e:
print(f"An error occurred while fetching post metadata: {e}")
return None, None
except Exception as e:
print(f"Unexpected error: {e}")
time.sleep(10)
return instagram_downloander(url, content_type)
This is my insta.py file and
elif user_state.get(user_id) == 'instagram_post':
url = update.message.text
content_type = 'post'
await update.message.reply_text("Please wait 1 minute for loading...")
media, media_type = instagram_downloander(url, content_type)
if media and media_type:
if media_type == 'video':
await update.message.reply_video(video=media, filename='instagram_video.mp4')
elif media_type == 'image':
await update.message.reply_photo(photo=media, filename='instagram_image.jpg')
else:
await update.message.reply_text("Unsupported media type.")
# Credit.deduct_credits(user_id, 1)
await update.message.reply_text(f"
本文标签:
serverPython Telegram botStack Overflow
版权声明:本文标题:server - Python Telegram bot - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:http://it.en369.cn/questions/1745654706a2161528.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论