Boto and Python on AWS - amazon-web-services

I am trying to get boto to work, but I am getting an error.
Installed boto via easy_install, or simply python ./setup.py install
cat boto.py
#!/usr/bin/python
import boto
conn = boto.connect_ec2()
3c075474c10b% ./boto.py
Traceback (most recent call last):
File "./boto.py", line 2, in <module>
import boto
File "/Users/vasiliyb/scripts/boto.py", line 3, in <module>
conn = boto.connect_ec2()
AttributeError: 'module' object has no attribute 'connect_ec2'

Just change the name of your module from "boto.py" to "myboto.py" (or whatever you like) and it will magically work.
You are basically redefining "boto" by naming your module boto.py.

Related

Accessing Mailman 3 list members via Python/Django management console

I am trying to access members of an existing Mailman 3 mailing list directly from Django Management console on a Debian Bullseye where Mailman is installed from deb packages (mailman3-full). I can connect to the Django admin console like this (all 3 variants seem to work fine):
$ /usr/share/mailman3-web/manage.py shell
$ mailman-web shell
$ mailman-web shell --settings /etc/mailman3/mailman-web.py
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
>>>
But inside the Django admin console, some mailman components seem to be missing.
I try to access the list manager as described here: Docs > Models > The mailing list manager:
>>> from mailman.interfaces.listmanager import IListManager
>>> from zope.component import getUtility
>>> list_manager = getUtility(IListManager)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python3/dist-packages/zope/component/_api.py", line 169, in getUtility
raise ComponentLookupError(interface, name)
zope.interface.interfaces.ComponentLookupError: (<InterfaceClass mailman.interfaces.listmanager.IListManager>, '')
Can't figure out why this ComponentLookupError happens.
Also tried to acccess a list with the ListManager implementation:
>>> from mailman.config import config
>>> from mailman.model.listmanager import ListManager
>>> list_manager = ListManager()
>>> list_manager.get('mynews#example.com')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python3/dist-packages/mailman/database/transaction.py", line 85, in wrapper
return function(args[0], config.db.store, *args[1:], **kws)
AttributeError: 'NoneType' object has no attribute 'store'
>>> list_manager.get_by_list_id('mynews.example.com')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python3/dist-packages/mailman/database/transaction.py", line 85, in wrapper
return function(args[0], config.db.store, *args[1:], **kws)
AttributeError: 'NoneType' object has no attribute 'store'
What am I doing wrong here? None of the examples in the Mailman 3 models documentation is working if I don't even get that far.
any help greatly appreciated!
It's just the wrong shell you are using. You should use Mailman core shell instead.
It is accessible via just mailman shell in your system most probably.
So mailman shell works great and I could run this interactively:
from mailman.interfaces.listmanager import IListManager
from zope.component import getUtility
from mailman.testing.documentation import dump_list
from operator import attrgetter
def dump_members(roster):
all_addresses = list(member.address for member in roster)
sorted_addresses = sorted(all_addresses, key=attrgetter('email'))
dump_list(sorted_addresses)
list_manager = getUtility(IListManager)
mlist = list_manager.get('ant#example.com')
dump_members(mlist.members.members)
but how could I put this into a script that could be run with mailman withlist -r listmembers -l ant#example.com?
from mailman.testing.documentation import dump_list
from operator import attrgetter
def listmembers(mlist):
roster = mlist.members.members
all_addresses = list(member.address for member in roster)
sorted_addresses = sorted(all_addresses, key=attrgetter('email'))
dump_list(sorted_addresses)
where would I put such a listmembers.py runner? I tried to put it into /usr/lib/python3/dist-packages/mailman/runners directory, but didn't work:
$ mailman withlist -r listmembers -l ant#example.com
ModuleNotFoundError: No module named 'listmembers'
Thanks!

Attribute Error: 'module' object has no attribute 'GraphKeys'

I'm currently trying to get a chatbot running with tensorflow.
The example for the chatbot is from this repository:
Github
I ran into some issues when I tried to run this in my tensorflow docker container.
When starting the script the script exits with an Attribute Error.
Traceback (most recent call last):
File "chatbot.py", line 5, in <module>
import tensorlayer as tl
File "/usr/local/lib/python2.7/dist-packages/tensorlayer/__init__.py", line 47, in <module>
from tensorlayer import initializers
File "/usr/local/lib/python2.7/dist-packages/tensorlayer/initializers.py", line 7, in <module>
from tensorlayer.layers.core import LayersConfig
File "/usr/local/lib/python2.7/dist-packages/tensorlayer/layers/__init__.py", line 12, in <module>
from .activation import *
File "/usr/local/lib/python2.7/dist-packages/tensorlayer/layers/activation.py", line 6, in <module>
from tensorlayer.layers.core import Layer
File "/usr/local/lib/python2.7/dist-packages/tensorlayer/layers/core.py", line 39, in <module>
TF_GRAPHKEYS_VARIABLES = tf.GraphKeys.GLOBAL_VARIABLES
AttributeError: 'module' object has no attribute 'GraphKeys'
I'm using the following Versions:
tensorflow 2.0.0a0
tensorlayer 1.11.1
Maybe some of you had already a similar issue and knows how I could solve this problem.
I solved this problem using pip install tensorflow==1.13.2
Maybe tl mismatch tf, you need to update your tensorlayer to 2.0+.you can use this instruction:
pip3 install https://github.com/tensorlayer/tensorlayer/archive/master.zip

Error in gcloud " AttributeError: 'module' object has no attribute 'DEFAULT_MAX_REDIRECTS'"

I am trying to implement firebase functions cron job from this link : https://github.com/firebase/functions-cron
Everything worked properly
But when I try to run google cloud cron job it gives me below error :
(/base/alloc/tmpfs/dynamic_runtimes/python27/c5586dbb532f7e5f_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py:263)
Traceback (most recent call last):
File "/base/alloc/tmpfs/dynamic_runtimes/python27/c5586dbb532f7e5f_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/alloc/tmpfs/dynamic_runtimes/python27/c5586dbb532f7e5f_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/alloc/tmpfs/dynamic_runtimes/python27/c5586dbb532f7e5f_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/s~debitcredit-7ecc0/20180506t121449.409523654918066893/main.py", line 18, in <module>
import pubsub_utils
File "/base/data/home/apps/s~debitcredit-7ecc0/20180506t121449.409523654918066893/pubsub_utils.py", line 24, in <module>
import oauth2client.contrib.appengine as gae_oauth2client
File "./lib/oauth2client/contrib/appengine.py", line 36, in <module>
from oauth2client import client
File "./lib/oauth2client/client.py", line 39, in <module>
from oauth2client import transport
File "./lib/oauth2client/transport.py", line 255, in <module>
redirections=httplib2.DEFAULT_MAX_REDIRECTS,
AttributeError: 'module' object has no attribute 'DEFAULT_MAX_REDIRECTS'
I tried this solution : Getting AttributeError: 'module' object has no attribute 'DEFAULT_MAX_REDIRECTS' when running Google Sheets API quickstart
But still no luck.
Can anyone please help me with this.
Issue is with your httplib Module.
When you installed this module for your project you must have installed it with pip for Python 3
If you want to check whether this module is for python 3 or python 2,
Go to httplib2 module and go inside its init.py
later see this line Requires Python 3 or later
if it is written like that means you have installed this library with pip for python 3. Now delete all the httplib2 from your lib folder.
Create a seperate enviroment for python 2.7 and again install all your modules with pip install -t lib -r requirements.txt

AttributeError: 'HTTPMessage' object has no attribute 'getparam'

I use python3 version in Ubuntu.
The code I use could run in python 2.7 version.
But I got some of Import Errors and Attribute Errors in python 3.
I want to edit this code for 3.6 version.
But I can't find any document for Attribute Error trouble shooting.
The error message I got is as below :
taylor#taylor-Rev-1-0:~/taylor/pyBook/ch2$ python parse_image.py
Traceback (most recent call last):
File "parse_image.py", line 35, in <module>
main()
File "parse_image.py", line 28, in main
charset = f.info().getparam('charset')
AttributeError: 'HTTPMessage' object has no attribute 'getparam'
and the methods or classes I imported is shown as below :
from urllib.request import urlopen
from html.parser import HTMLParser
charset = response.headers.get_content_charset()
you can use this in python3

import asgi_redis: ImportError: No module named _compat

I can import asgi_redis on my local server fine but I get the error in the title when i try to import asgi_redis on my production server (heroku, using heroku run bash). Both have the same version of asgi_redis.
Here is the full traceback:
>>> import asgi_redis
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/app/.heroku/python/lib/python2.7/site-packages/asgi_redis/__init__.py", line 1
, in <module>
from .core import RedisChannelLayer
File "/app/.heroku/python/lib/python2.7/site-packages/asgi_redis/core.py", line 10, i
n <module>
from redis._compat import b
ImportError: No module named _compat
Does anyone know what is going on here? Thanks in advance.
I also have redis installed, redis 2.6.0, FWIW
local server had latest redis, production did not. upgraded redis on production and error is gone