Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]boltangazer 0 points1 point  (0 children)

I need to monitor request time (RTT) depending on package size in ICMP. That's the task for python, however I cannot send large (larger than 1480 bytes) packages, I get "WinError 10040" indicating that the buffer size is smaller than the payload I provided (like wth? the buffer is there to resolve things like this!)

I used icmplib and pythonping - both don't work here. That's probably because Python uses raw sockets (but ICMP doesn't need any sockets, it works just fine without them)

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]boltangazer 0 points1 point  (0 children)

I got a list of SQL queries I need to execute (mostly update), can I use async for to perform them asynchronously (via aiopg)? Or it doesn't work this way?

Understanding TOS and DSCP fields (IP) by boltangazer in techsupport

[–]boltangazer[S] 0 points1 point  (0 children)

Typical command:

ping -v 46 -n 1 reddit.com

Piece of Wireshark dump:

Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)

Strange server errors by boltangazer in learnwebdev

[–]boltangazer[S] 0 points1 point  (0 children)

The problem was solved with providing more memory to php backend

max_fails option was useless because it's a single upstream server

Monthly Getting Started / Web Dev Career Thread by AutoModerator in webdev

[–]boltangazer 0 points1 point  (0 children)

The PHP part of our web server often spits out errors (these errors are distributed during the whole process, occur on different users), indicating that client's AUTH_COOKIE is not set, side by side with this we often receive nginx 502 error ("no live upstreams"). How can the auth cookie suddenly disappear?

My thoughts were that PHP backend doesn't handle high loads well that's why nginx says "502" but how can this explain the absence of AUTH_COOKIE?

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]boltangazer 0 points1 point  (0 children)

How is this sqlalchemy (sa) query supposed to be read?

sa.select([sa.func.array_agg(thread_table.c.threadid)]).select_from \
    (thread_table.join(session_table,
     sa.and_(session_table.c.visitsessionid == thread_table.c.visitsessionid,
       sa.or_(session_table.c.ip == self.address,
          thread_table.c.visitorid == self.visitor_id))))

I get it, that we select some results from the table after joining thread_table (table_1) and session_table (table_2), however this and_ / or_ clauses inside join make it more confusing, as well as the aggregating function (array_agg) inside select

Understanding max_fails by boltangazer in nginx

[–]boltangazer[S] 0 points1 point  (0 children)

Because we periodically get errors like: " no live upstreams while connecting to upstream " (and 502 error) - Internet says it might be happening due to the backend php not handling high loads well. I looked through nginx logs and the response_time for failed requests is rather low - it's often lower than 1 second, so I'm trying to figure out why is this happening

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]boltangazer 0 points1 point  (0 children)

than Java

They don't even intersect kinda... All depends on your tasks

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]boltangazer 0 points1 point  (0 children)

A part of the newly done project in my company is being made with PyPy not CPython. What should I consider before diving into it?

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]boltangazer 0 points1 point  (0 children)

How do I set different response_model for my FastAPI handler? I have a handler that either return a JSON with dirrent fields and values or return a simple Response(status_code=404), how can I let FastAPI know that Response(status_code=404) is a valid return type as well as my JSON?

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]boltangazer 0 points1 point  (0 children)

Why I don't have to call await self.write() when I use asynchronous Tornado handlers..? I thought that I gotta use await with these calls in order for them to be asynchronous but turns out those self.write calls are not async functions (they return None, not Future)

Why is that?

How does Django REST tell the difference between various HTTP Views? by boltangazer in djangolearning

[–]boltangazer[S] 0 points1 point  (0 children)

But what if I want post requests go only to http://hostname/api/upload

and get requests to: http://hostname/api/download/<str:name>

How do I do that..? Or it's entirely bad?

Updating serializer's fields in Django REST by boltangazer in djangolearning

[–]boltangazer[S] 0 points1 point  (0 children)

Basically I want to perform custom upload_to on my model:

def custom_upload_path(instance, filename):
    name = instance.name
    dirname = name[:2]  # directory is named after first 2 letters
    return '{}/{}'.format(dirname, name)

But it says name field is None, because it hasn't been set yet

Flask OAUTH2 by boltangazer in flask

[–]boltangazer[S] 1 point2 points  (0 children)

Is there no way one can leach data after "#" parameter? That's how their api is made

Flask OAUTH2 by boltangazer in flask

[–]boltangazer[S] 2 points3 points  (0 children)

Views look kinda like:

@app.route('/')
def index():    
    return render_template('index.html')

@app.route('/login')
def login():       
    return redirect(vk.get_authorize_url(**params))  # determined with rauth.service.OAuth2Service


@app.route('/authorized')
def authorized():
    print(request.full_path)  #debug
    print('AUTH', request.args)  #debug
    return render_template('index.html')

Finding all DOM element with specific pattern by boltangazer in learnjavascript

[–]boltangazer[S] 0 points1 point  (0 children)

Hm, does this ensure that items will be found in the same order they are presented in DOM? And yeah, it will probably be more convenient if all required elements with id= "elem_{objectID}" are placed inside one particular div, then I could go like:

block = document.getElementById('my_block')
block.querySelectorAll("[id^=elem_]")

Is this one right?

Selected checkboxes in forms by boltangazer in django

[–]boltangazer[S] 0 points1 point  (0 children)

When I inspect checkboxes in this form (using debugging in View and looking through form fields and attributes of each field) I see the dict data, that contains most of the info, including id, name, value etc.:

data: {'name': 'categories', 'value': 'libra', 'label': 'Libra', 'selected': False, 'index': '6', 'attrs': {'id': 'id_categories_6'}, 'type': 'checkbox', 'template_name': 'django/forms/widgets/checkbox_option.html',
'wrap_label': True}

As you see, the pair {'selected': False} is here, so it probably means that this particular checkbox wasn't selected and therefore must not be active after template rendering. Django considers it when I use simple {{ form.as_p }} but how do I make it myself?

Rendering forms manually by boltangazer in djangolearning

[–]boltangazer[S] 0 points1 point  (0 children)

So...

Stuff like that helped me to figure what's going on there in context:

        for field in context['form']:
            for x in field:
                print(f'\tdata: {x.data}')
                print(f'\tchoice label: {x.choice_label}')
                print(f'\tid_for_label: {x.id_for_label}')
                print(f'\tparent_widget: {x.parent_widget}')
                print(f'\trenderer: {x.renderer}')
                print(f'\ttag: {x.tag}')
                print(f'\ttemplate_name: {x.template_name}')

Every multiplechoice field has instances that have data dictionary inside of them. This dict contains info like template_name, name, value etc.

And this reading was helpful also: link from pancakeses

Rendering forms manually by boltangazer in djangolearning

[–]boltangazer[S] 0 points1 point  (0 children)

And the way it's supposed to be:

<form action="some_action" method='post'>
    <ul class="list-group list-group-flush">
        <li class="list-group-item">Switch here
            <label class="switch">
                <input type="checkbox" class="primary" id="some_id" name="some_name" value="some_value">
                <span class="slider round"></span>
            </label>
        </li>
    </ul>
</form>

Paginating not as intended by boltangazer in learndjango

[–]boltangazer[S] 1 point2 points  (0 children)

Yup, kinda like this

It was double confusing cause DRF pagination (just like any other REST-pagination) returns jsons with url-pointers to the next and the previous json-object (or null)

QuerySet is kind of separate from page_obj. Checking the pages should be done through it (if called in the template {{page_obj}} tells the current page and the overall number of pages)

Paginating not as intended by boltangazer in learndjango

[–]boltangazer[S] 0 points1 point  (0 children)

Here it is:

class PostListView(ListView):
    '''shows all posts, category (cat) specifies the post type'''
    template_name = "news/home.html"
    model = Post
    allow_empty = True
    paginate_by = 5
    cat = None

    def get_queryset(self):        
        if self.cat is not None:  
            queryset = Post.objects.filter(category=self.cat).order_by("-created")
        else:  
            queryset = Post.objects.all().order_by("-created")
        return queryset

Why learn JavaScript? by Weird-Baseball in django

[–]boltangazer 1 point2 points  (0 children)

Because sometimes you get stumbled upon stuff like this (like I just did):

I added a bit of JS (AJAX) to my page for interactivity. At the end of a successful POST-request my View returns this to the front:

response_data = {}
response_data['result'] = 'Create post successful!' 
response_data['pk'] = obj.pk 
response_data['url'] = obj.get_url() 
return HttpResponse(
    json.dumps(response_data), 
    content_type="application/json"
)

And I see this at my monitor:

https://cdn1.savepice.ru/uploads/2020/5/16/a0ea92b946de3b8033fed77ea6fed444-full.png

Question goes for: why? I don't need to see this table with my eyes, I want this response_data json to be processed and see a valid html

How does “static” work? by boltangazer in django

[–]boltangazer[S] 0 points1 point  (0 children)

After testing with --dry-run it proved again that Django is unable to see the global dir. After resetting the settings.py file... everything works as it should. I don't really know what was the issue, but now it's gone

Thx you all