pyQiwiP2P pay_sources: list[str] = None - python

I need to make payment via qiwi
from pyqiwip2p import QiwiP2P
from pyqiwip2p.Qiwip2p import PaymentMethods
def create_trans(amount=400, lifetime=30, comment="def"):
p2p = QiwiP2P(auth_key="I specifically removed")
bill = p2p.bill(amount=amount, lifetime=lifetime, comment=comment, bill_id=random_id, pay_sources=[PaymentMethods.qiwi, PaymentMethods.card, PaymentMethods.mobile])
return bill
The program ends with an error:
File "G:\bot\venv\lib\site-packages\pyqiwip2p\Qiwip2p.py", line 118, in QiwiP2P
pay_sources: list[str] = None,
TypeError: 'type' object is not subscriptable

This looks to be a bug in pyQiwiP2P.
As per your traceback, line 118 of pyqiwip2p.Qiwip2p.py is as follows:
pay_sources: list[str] = None,
This contains a broken type hint, list[str]. It seems the author wanted to add a type hint saying that the method parameter pay_sources should contain a list of strings. In this case, they should write
pay_sources: typing.List[str] = None,
or perhaps
pay_sources: typing.Union[typing.List[str], None] = None,
instead, given that pay_sources can also be None.
To confirm this is the case, we can easily reproduce your exception in a Python interactive session:
>>> def test(a: list[str]):
... pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable
I would suggest you get in contact with the package author, perhaps by raising an issue on the project's GitHub repository.

Perhaps you are using a version of python later than 3.9. I solved this problem by downloading an older version of the pyQiwiP2P library before deleting the one that was already on my PC:
pip uninstall pyQiwiP2P
pip install pyQiwiP2P==2.0.1

Related

mypy typing leeds to unexpected traceback

I'm trying to use a work-around for the problems described in this GitHub issue ("Class with function fields incorrectly thinks the first argument is self").
from dataclasses import dataclass
from typing import TypeVar, Generic, Any, Iterable, List
T = TypeVar("T")
# See https://github.com/python/mypy/issues/5485
#dataclass
class Box(Generic[T]):
inner: T
#property
def unboxed(self) -> T:
return self.inner
I run into a traceback like this, though:
However, upon importing (only(!) ) the code above from another module I run into a traceback like this:
(py) sugarline:~/src/oss/ormsnack write-compile-eval
Traceback (most recent call last):
[.....]
File "/Users/jacob/src/oss/ormsnack/ormsnack/ng_desc.py", line 8, in <module>
from kingston.kind import Box # type: ignore
File "kingston/kind.py", line 12, in <module>
AttributeError: attribute '__dict__' of 'type' objects is not writable
Googling only lands me in old bugs that seem to have gone stale, though (https://bugs.python.org/issue38099, https://github.com/man-group/arctic/issues/17), etc.
Is anyone able to figure out a work-around?

Facebook scraper 'NoneType' object has no attribute 'find' while get_post

While i using facebook_scraper libraries to get post from facebook page with this code.
from facebook_scraper import get_posts
for post in get_posts('ThaiPBSFan', pages = 50):
print(post['text'][:100])
It work with few post, then error like this.
Traceback (most recent call last):
File ".\main.py", line 2, in <module>
for post in get_posts('ThaiPBSFan', pages = 50):
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\facebook_scraper.py", line 75, in _get_posts
yield _extract_post(article)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\facebook_scraper.py", line 102, in _extract_post
text, post_text, shared_text = _extract_text(article)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\facebook_scraper.py", line 137, in _extract_text
nodes = article.find('p, header')
AttributeError: 'NoneType' object has no attribute 'find'
So what's a problem and how can i fix it.
From the traceback, it seems that facebook_scraper is not returning a valid post; this may be because there are no further posts to find on the page.
Therefore, you could use a try/except block to catch this exception, i.e.:
try:
for post in get_posts('ThaiPBSFan', pages=50):
print(post['text'][:100])
except AttributeError:
print("No more posts to get")
It's not ideal as you would preferably be able to get a more specific exception once there were no more posts to retrieve, but it should work in your case. Be careful with the code insider your try clause - if an AttributeError is raise anywhere else, you will miss it.
I had the same issue, but only when using the most recent version of the package (0.1.12). Try with an older version of the package. For example, I tried the version 0.1.4 and it worked well. To install it, write:
pip install facebook_scraper==0.1.4
in your terminal.

TypeError: expected string or bytes-like object and works on server but not on PC

Introduction
I have problem with python program written in python 3.4.2. At the beginning i want to say, that it's not my program.
When i connect with server by SSH and compile it, it works just fine.
Server and PC specification
:
...and from my PC:
I have different Python version, but i can't compile it at 3.4.2, because there is no typing module for this specific version, which i need. I don't know if GCC version could cause this problem, but i've tried different versions.
I've downloaded it, and tried to compile it by myself. I run it in the exactly same way.
The real problem
Traceback (most recent call last):
File "gads.py", line 28, in <module>
lists = list_working.ListWorking(files_data)
File "/home/grzesiek/googleads/lib/list_working.py", line 43, in __init__
self._acc = self._split_str_list(list_data['accepted']['content'])
File "/home/grzesiek/googleads/lib/common.py", line 69, in _split_str_list
splited = re.split(separator, content)
File "/usr/local/lib/python3.5/re.py", line 203, in split
return _compile(pattern, flags).split(string, maxsplit)
TypeError: expected string or bytes-like object
So far i know that ListWorking(files_data) passes some files which are dictionaries, and at the end when i want to use regex it throws an error. But i can't change these dictionaries to strings or lists, because then it compiles, but erase data that i provide to ListWorking()
Here is fragment of code which i've tried to change:
def __init__(self, list_data: dict) -> None:
self._acc = self._split_str_list(list_data['accepted']['content'])
self._acc = self._del_dup(self._acc)
self._ign = self._split_str_list(list_data['ignored']['content'])
self._ign = self._del_dup(self._ign)
self._pro = self._split_str_list(list_data['protected']['content'])
self._pro = self._del_dup(self._pro)
self._fign = self._split_str_list(list_data['full_ignored']['content'])
self._fign = self._del_dup(self._fign)
self._key = self._split_str_list(list_data['keywords']['content'])
self._key = self._del_dup(self._key)
self._unk = self._split_str_list(list_data['unknown']['content'])
self._unk = self._del_dup(self._unk)
self._sw = self._split_str_list(list_data['stopwords']['content'])
And where the last error occurs:
def _split_str_list(content: str, separator: str = '\n') -> list:
"""Split string to list"""
splited = re.split(separator, content)
splited = list(x.strip() for x in splited)
splited = list(filter(None, splited))
return splited
Also, in Python 3.4.2 it comes to import typing and throws an error, because there is no typing lib in this version of Python.
So - how is it possible to work fine on Linux server but it doesn't on my PC?
Well, the answer was much simpler than i thought it would be...
I just had to install correct version of enca, code author didn't wrote the specific informations if something is missing, so it was very hard to find, because whole project has about ~5000 lines of code, and enca was used only by one function.
It had nothing to do with Linux or GCC.

Python jsonpickle error: 'OrderedDict' object has no attribute '_OrderedDict__root'

I'm hitting this exception with jsonpickle, when trying to pickle a rather complex object that unfortunately I'm not sure how to describe here. I know that makes it tough to say much, but for what it's worth:
>>> frozen = jsonpickle.encode(my_complex_object_instance)
>>> thawed = jsonpickle.decode(frozen)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/jsonpickle/__init__.py",
line 152, in decode
return unpickler.decode(string, backend=backend, keys=keys)
:
:
File "/Library/Python/2.7/site-packages/jsonpickle/unpickler.py",
line 336, in _restore_from_dict
instance[k] = value
File "/Library/Python/2.7/site-packages/botocore/vendored/requests/packages/urllib3/packages/ordered_dict.py",
line 49, in __setitem__
root = self.__root
AttributeError: 'OrderedDict' object has no attribute '_OrderedDict__root'
I don't find much of assistance when googling the error. I do see what looks like the same issue was resolved at some time past for simpler objects:
https://github.com/jsonpickle/jsonpickle/issues/33
The cited example in that report works for me:
>>> jsonpickle.decode(jsonpickle.encode(collections.OrderedDict()))
OrderedDict()
>>> jsonpickle.decode(jsonpickle.encode(collections.OrderedDict(a=1)))
OrderedDict([(u'a', 1)])
Has anyone ever run into this themselves and found a solution? I ask with the understanding that my case may be "differently idiosynchratic" than another known example.
The requests module for me seems to be running into problems when I .decode(). After looking at the jsonpickle code a bit, I decided to fork it and change the following lines to see what was going on (and I ended up keeping a private copy of jsonpickle with the changes so I can move forward).
In jsonpickle/unpickler.py (in my version it's line 368), search for the if statement section in the method _restore_from_dict():
if (util.is_noncomplex(instance) or
util.is_dictionary_subclass(instance)):
instance[k] = value
else:
setattr(instance, k, value)
and change it to this (it will logERROR the ones that are failing and then you can either keep the code in place or change your OrderedDict's version that have __root)
if (util.is_noncomplex(instance) or
util.is_dictionary_subclass(instance)):
# Currently requests.adapters.HTTPAdapter is using a non-standard
# version of OrderedDict which doesn't have a _OrderedDict__root
# attribute
try:
instance[k] = value
except AttributeError as e:
import logging
import pprint
warnmsg = 'Unable to unpickle {}[{}]={}'.format(pprint.pformat(instance), pprint.pformat(k), pprint.pformat(value))
logging.error(warnmsg)
else:
setattr(instance, k, value)

how to access Flickr API using Python?

I installed everything as it says on the FlickrAPI homepage but when I try to run:
import flickrapi
api_key = '1a4c975fa83048436a2086bcab7d2290'
api_password = '5e069eae20e60297'
flickrclient = flickrapi.FlickAPI(api_key, api_password)
favourites = flickrClient.favorites_getPublicList(user_id='userid')
photos = flickr.photos_search(user_id='73509078#N00', per_page='10')
sets = flickr.photosets_getList(user_id='73509078#N00')
for photo in favourites.photos[0].photo:
print photo['title']
I get this message from the command prompt:
C:\Users\Desktop>python api.py
Traceback (most recent call last):
File "api.py", line 4, in <module>
flickrclient = flickrapi.FlickAPI(api_key, api_password)
AttributeError: 'module' object has no attribute 'FlickAPI'
Any ideas?? I have tried almost everything
FlickAPI is not the same as FlickrAPI. You're missing an r.
The file C:\Users\XXXXXX\Desktop\FLICKR API\flickrapi.py is not part of the flickrapi package. Please rename it, it is masking the real library. Right now it is being imported instead of the installed package.
The flickrapi package itself consists of a directory with a __init__.py file inside of it. Printing flickrapi.__file__ should result in a path ending in flickrapi\__init__.py.
In your "flickrclient = flickrapi.FlickAPI" line, you're missing an 'r' in FlickAPI.
Also, on the next line, your *"user_id='userid'"* argument needs an actual user ID, such as '999999#N99'
Hopefully you found that & got this working a few months ago! :)

Categories