Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: KeyError: 'target' #159

Open
2 tasks done
kekwak opened this issue Apr 25, 2024 · 4 comments
Open
2 tasks done

[Bug]: KeyError: 'target' #159

kekwak opened this issue Apr 25, 2024 · 4 comments
Assignees

Comments

@kekwak
Copy link

kekwak commented Apr 25, 2024

Debug Tips

  • I'm sure I've read this project's Issues of README.

What happened?

i tried to print data in module before bug happens

print(data)
return data if is_detail_result else '\n'.join([self.decrypt(item) for item in data['target']])

so i got {'http_code': 200, 'message': 'Token expired', 'err_code': None, 'details': None, 'auth_code': -3}

i use caiyun:
out = ts.translate_text(text, translator='caiyun', from_language='en', to_language='ru')

APP Version

5.9.1

Python Version

3.11

Runtime Environment

Windows 11

Country/Region

Russia

Relevant log output

File "C:\Основная папка\Рабочий стол\KABYTE\Git Tasks\KABYTE_2024\08_Final_Project\misc\pipe.py", line 123, in translate
    out = ts.translate_text(text[start:end], translator=translator, from_language=src_lang, to_language=dest_lang)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Основная папка\Рабочий стол\KABYTE\Git Tasks\KABYTE_2024\08_Final_Project\.venv\Lib\site-packages\translators\server.py", line 5470, in translate_text
    return self.translators_dict[translator](query_text=query_text, from_language=from_language, to_language=to_language, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Основная папка\Рабочий стол\KABYTE\Git Tasks\KABYTE_2024\08_Final_Project\.venv\Lib\site-packages\translators\server.py", line 117, in _wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "c:\Основная папка\Рабочий стол\KABYTE\Git Tasks\KABYTE_2024\08_Final_Project\.venv\Lib\site-packages\translators\server.py", line 288, in _wrapper
    return func(*args, **{**kwargs, **{'query_text': query_text}})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Основная папка\Рабочий стол\KABYTE\Git Tasks\KABYTE_2024\08_Final_Project\.venv\Lib\site-packages\translators\server.py", line 2019, in caiyun_api
    return data if is_detail_result else '\n'.join([self.decrypt(item) for item in data['target']])
                                                                                   ~~~~^^^^^^^^^^
KeyError: 'target'

Screenshots

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@UlionTse
Copy link
Owner

@kekwak Bro, look this: #157 (comment)

The same problem, one, is that it is not clear what the input text is. Second, whether this bug can be reproduced. Third, through the parameters is_detail_result=True, see what the server returned.

translators_issues159

@UlionTse
Copy link
Owner

{'http_code': 200, 'message': 'Token expired', 'err_code': None, 'details': None, 'auth_code': -3},
Noting this, it is recommended that you use parameters update_session_after_freq and update_session_after_seconds to update the session and other cached values early.

@kekwak
Copy link
Author

kekwak commented Apr 29, 2024

I tried to use update_session_after_freq and update_session_after_seconds, but still got this error

out = ts.server.caiyun(
	textz, translator='caiyun', from_language='en', to_language='ru',
	update_session_after_freq=1, update_session_after_seconds=5,
)

with is_detail_result=True I've got this:
{'http_code': 200, 'message': 'Token expired', 'err_code': None, 'details': None, 'auth_code': -3}

text, that I've used:
'As the hours pass and the days unfold from the mysterious image that captivates with its futuristic and abstract allure, a series of events begin to unravel in a mesmerizing dance of technology and spirituality.\n\nThe central figure, exuding an aura of profound significance akin to a deity or spiritual being, seems to emanate a powerful energy that pulses through the surroundings. The symbols and objects surrounding this enigmatic figure come to life, shimmering with an otherworldly glow as if unlocking hidden secrets of the universe.\n\nThe silhouette of a person, glowing with a celestial blue light, stands at the forefront, their presence commanding attention amidst the intricate network of symbols and shapes. A large circular object beams with a mesmerizing blue light, casting a soft, enchanting glow that intertwines with the complex patterns scattered throughout the background.\n\nAs time unfolds, the deep shades of purple blend with the ethereal blues and pinks, creating a dreamlike ambiance that hints at revelations beyond comprehension. The eyes, triangles, and geometric shapes pulse with a rhythmic energy, as if propelling the narrative towards a climactic revelation.\n\nWithin this enigmatic setting, a subtle tension builds, hinting at a convergence of forces beyond human understanding. The interplay of light and shadow, of ancient symbols and futuristic motifs, sets the stage for a profound awakening, a moment where the boundaries between the physical and the metaphysical blur into a harmonious symphony of existence.\n\nAs the days stretch ahead, the image remains a portal to a realm where technology and spirituality converge in a dance of cosmic proportions. Each symbol, each object holds a key to a deeper truth waiting to be unlocked, promising a journey of enlightenment and transformation for those brave enough to venture into its enigmatic depths.'

Speaking about bug reproducing, try to hold you prog for a while, I use it in telegram bot and after some time this issue appears. It this way I'm not able use it, that's why I have to restart my bot, then it starts working.

@UlionTse
Copy link
Owner

UlionTse commented May 8, 2024

@kekwak Bro
Once it is identified by anti-crawlers due to frequent requests, the impact will be directly on the IP address level. Therefore, any parameter you change within a short period of time will be invalid. The two parameters I suggest you use are not that the smaller the value, the better. If it is too small, it will obviously be regarded as a crawler. If it is too large, it will not meet the browser session time. It is necessary to set an appropriate size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants