How to get a telegram bot to send an svg image https://phys-ege.sdamgia.ru/get_file?id=69140

70 Views Asked by At

I'm making a telegram bot that sends tasks from the site https://phys-ege.sdamgia.ru / You need to send an Image.

As I understand it, you need to convert svg to png or jpeg, but when using the pyvips library it gives an error

Traceback (most recent call last):
  File "D:/Питончик/hbntdfg.py", line 1, in <module>
    import pyvips
  File "C:\Users\denve\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvips\__init__.py", line 70, in <module>
    gobject_lib = ffi.dlopen(_gobject_libname)
  File "C:\Users\denve\AppData\Local\Programs\Python\Python311\Lib\site-packages\cffi\api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "C:\Users\denve\AppData\Local\Programs\Python\Python311\Lib\site-packages\cffi\api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "C:\Users\denve\AppData\Local\Programs\Python\Python311\Lib\site-packages\cffi\api.py", line 828, in _load_backend_lib
    return backend.load_library(path, flags)
OSError: cannot load library 'C:\Program Files (x86)\GTK2-Runtime\bin\libgobject-2.0-0.dll': error 0xc1
2

There are 2 best solutions below

0
jcupitt On

I think you are seeing DLL clashes.

pyvips is trying to open libgobject-2.0-0.dll and it's finding the one you have in C:\Program Files (x86)\GTK2-Runtime. This is probably pretty old and won't work with libvips, which needs quite a recent libgobject.

Have a look at the win install notes:

https://github.com/libvips/pyvips#windows-install

And make sure you follow the instructions for python 3.8 and later.

1
denverskill On
        x=1
        r=random.randint(1,69)
        url = 'https://phys-ege.sdamgia.ru/test?theme=403&print=true'
        response = requests.get(url)
        soup = BS(response.content, "html.parser")
        data = soup.find_all('div', class_="nobreak")
        data_2 = soup.find_all('div', style= "clear:both;display:none")
        for i in data:
            v = i.find('p',class_= "left_margin")
            if x == r:
                try:
                    z = v.find('img').get('src')
                    svg2png(url='https://ege.sdamgia.ru'+ z,write_to='task.png')
                    photo = open("D:/Питончик/task.png","rb")
                    bot.send_photo(chat_id=message.chat.id, photo=photo)
                except AttributeError:
                    print('No photo')
                bot.send_message(message.chat.id,v.text)