Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8109513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:26:29+00:00 2026-06-06T01:26:29+00:00

Let me start by saying that I’ve never coded in Python. I need to

  • 0

Let me start by saying that I’ve never coded in Python.

I need to make an API call to upload a bunch of files from my local machine to a server. On the server, I want to take the file name of the files and assign the string sans the extension to a variable called ‘identifier.’

import requests
import os
url = 'http://someplace'
folder = 'path/to/folder/'
for card in os.listdir(folder):
    data = {'identifier': PyFile_Name(PyObject *p), 'type': 'Inventory Card'}
    files = {'card': open(os.path.join(folder, card), 'rb')}
    requests.post(url, data=data, files=files, auth=('username', 'pass'))

Am I doing this right?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:26:32+00:00Added an answer on June 6, 2026 at 1:26 am

    You should be using

    import requests
    import os
    url = 'http://someplace'
    folder = 'path/to/folder/'
    for card in os.listdir(folder):
        data = {'identifier': '.'.join(card.split('.')[:-1]), 'type': 'Inventory Card'}
        files = {'card': open(os.path.join(folder, card), 'rb')}
        requests.post(url, data=data, files=files, auth=('username', 'pass'))
    

    '.'.join(card.split('.')[:-1]) takes the filename (in card), splits it into components that were separated by a period in the file name, rejects the last element of the list [:-1] and rejoins the filename minus the extension.

    Using this syntax will handle filenames with multiple periods such as foo.20120613.txt

    EDIT:

    An example that lists files in my ~/tmp directory…

    [mpenning@Bucksnort tmp]$ ls
    howto  regex_trial.xml  soln.py
    [mpenning@Bucksnort tmp]$
    [mpenning@Bucksnort tmp]$ python
    Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
    [GCC 4.4.5] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> for card in os.listdir('./'):
    ...     print "card:", card
    ...     print " base_name:", '.'.join(card.split('.')[:-1])
    ...
    card: howto
     base_name:
    card: regex_trial.xml
     base_name: regex_trial
    card: soln.py
     base_name: soln
    >>>
    

    Note that howto is a directory… you need to put logic in your script to skip a directory if there is one in this path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me start by saying that this app was working fine the day before.
First off, let me start by saying that I am totally new to working
Firstly, let me start by saying that I haven't ever directly used SQL views.
Let me start out by saying that I'm not a C developer and I
Let me start by saying, I like the border that chrome is using for
Let me start by saying this is a homework assignment, I don't need any
Let me start by saying that, Yes! I did go through Questions with similar
Let me start by saying that I know nothing about Cron, so sorry. How
Let me start of by saying that as I don't know how to search
Let me start out by saying that I feel like there should be a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.